After getting past a few hurdles learning Git, I came across a new challenge: Renaming a directory (locally, in the working directory).
When I type git status, it lists all the files in the old directory name (that exist with the same exact filenames in the new directory) as deleted and the new directory name as “untracked”.
Is there a way to tell Git that “it’s actually the same directory, just a different name”?
So that all the files will be listed by git status as modified only?
To exemplify the problem, here is the output I receive from git status when I rename an entire directory:
git status
# On branch master
# Changes not staged for commit:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: old-dir-name/file1
# deleted: old-dir-name/file2
# deleted: old-dir-name/file3
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# new-dir-name/
no changes added to commit (use "git add" and/or "git commit -a")
~/sb/ws>
All answers here were very helpful on the way to the actual solution for the particular scenario I was facing. I am providing what worked for me in the form of actual steps, hopefully helping others encountering the same challenge:
git mv <old-dir-name><new-dir-name>
git status(verify that all filesmarked renamed, not “deleted”)
git commit -a -m "git mv<old-dir-name> <new-dir-name>"
(this is a “fake” commit, to prepare
for the real rename in the next
steps)
git branchgit_mv_20110708_1500_DO_NOT_USE
(“fake” branch with timestamp
reminding that we only did this as a
workaround)
/bin/rm -Rf <new-dir-name>cp -Rp .../<new-dir-name> .(copyover the actual folder with the
renamed name)
git status(most modified fileswill now be marked correctly as
modified, not “deleted”. Files that have been renamed will be
marked as deleted and added,
despite having the same content! — repeated steps 1-7 for those files if rename tracking is needed for them too)
git add <untracked files>git commit -a -m "finally renamedthis folder"
git branch FOLDER_RENAMED🙂P.S.
gitkloves this, butEmacsis still confused with the renames. 🙁