Max Nanasy
Max Nanasy

Reputation: 6141

Can git detect a rename in which the delete occurs in a commit before the add?

Example:

After the following sequence of commands:

echo "abc
> def
> ghi" > a
git add a
git commit -m "Add a"
git rm a
git commit -m "Remove a"
git show HEAD^:a > b
git add b
git commit -m "Add b"

Are there any arguments that could be passed to git log that would show a renamed to b?

I ask mainly because SVN supports this use case by doing svn cp $REPO/a@$REVISION b, in which $REVISION is a revision in which a does not exist; this will cause svn log b to show the history of both a and b.

Upvotes: 3

Views: 126

Answers (1)

Karl Bielefeldt
Karl Bielefeldt

Reputation: 49148

Currently, the delete and add have to be in the same commit in order for git to detect it as a rename. That doesn't mean someone couldn't add that functionality in the future (even you if you wanted). That also doesn't mean you can't put them into the same commit later. If you accidentally do this before you push, you can combine the commits using rebase -i or merge --squash and the rename will be detected using the standard git log --follow command.

Upvotes: 1

Related Questions