mark mark - 1 year ago 122
Git Question

How to do "hg mv --after" in git?

I renamed some files outside of git and modified them heavily. When I am running

git diff-index -M --name-status HEAD
I see only 4 files as renamed/moved, whereas it should be more.

I know that I can record the move post factum in Mercurial using
hg mv --after
. I cannot find an equivalent in git. Is there?

Answer Source

Summary: Don't worry about it. Just commit the file normally, because that's literally your only choice.

Here's how Git views a rename from X to Y.

Commit #1:
  - File named "X" with contents "Hello, world!"
Commit #2:
  - File named "Y" with contents "Hello, world!"

Notice that Git does not actually care if you renamed the file or if you created a new file with the same contents. To Git, there is no difference at all.

Git does not record moves in the repository, and there is no per-file history. Git only records history as a graph of snapshots of the entire repository. Simply use git add and git commit as normal, nothing else you do here will have any effect. If you use git mv it is just the same as git rm and git add.

When you use git status or git log, it will display a deletion and addition as a move if the added file is similar enough to the deleted file. Git does not use any extra information in the repository. If you change the moved file enough, it will show up as a separate addition and deletion instead. Git does this by comparing the contents of the new file to the contents of the deleted file. This happens when you ask for the diff, after the data is already committed.

The default similarity threshold is 50%. If you want to see renames between files that are less than 50% similar, pass a lower percentage to git diff-index. For example, to track renames even if 75% of the file changes, use this:

git diff-index -M25%
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download