Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git not following a moved file

I moved a couple of files that are in my project, but I did the move inside finder on my mac. I see that git source control treated the files as an add.

I haven't done a commit yet. git status shows the following:

  • Under Changes to be committed, the updated/moved files are listed as new files
  • Under the Changes not staged for commit, the updated/moved files are listed as modified, the original files are listed as deleted.

Now when I do a version compare with these files in Xcode, the viewer has no history.

I looked at the accepted answer here and tried git log --follow ./pathtomynewfile. That gave no result.

Viewing changes in the version editor has become a valuable tool, and I would like to continue under these circumstances.

What can I do to tie to old version history to the new, relocated version?

like image 231
Jim Avatar asked Dec 17 '25 22:12

Jim


2 Answers

Git won't necessarily show something as a "move" until after you've made a commit. This operation is not identified when the commit is done, but is done after the fact by tools (such as git log --follow). Basically, when Git tools see that a new file has appeared in the history, it looks around for other files that it might have come from (if the same or similar file was deleted in the same commit, then Git calls it a move).

like image 192
Greg Hewgill Avatar answered Dec 19 '25 13:12

Greg Hewgill


Either use git mv, or git add the new file, and git rm the old file. Both add and rm need to be in the index when committing, otherwise git does not recognize it as a rename.

like image 30
user1338062 Avatar answered Dec 19 '25 15:12

user1338062



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!