How to tell Git that it's the same directory, just a different name

后端 未结 5 1190
暗喜
暗喜 2020-12-03 07:08

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<

5条回答
  •  伪装坚强ぢ
    2020-12-03 07:34

    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:

    1. git mv
    2. git status (verify that all files marked renamed, not "deleted")
    3. git commit -a -m "git mv " (this is a "fake" commit, to prepare for the real rename in the next steps)
    4. git branch git_mv_20110708_1500_DO_NOT_USE ("fake" branch with timestamp reminding that we only did this as a workaround)
    5. /bin/rm -Rf
    6. cp -Rp .../ . (copy over the actual folder with the renamed name)
    7. git status (most modified files will 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)
    8. git add
    9. git commit -a -m "finally renamed this folder"
    10. git branch FOLDER_RENAMED :)

    P.S. gitk loves this, but Emacs is still confused with the renames. :(

提交回复
热议问题