I really need this command in git
hg addremove
So now look at scenario and see how mercurial would save me in here:
I had some kind of dir in here var/htdocs/static/static. I accidentally moved files to wrong location (with git-mv). anyway… now I moved some folders around by hand:
mv static static2
mv static2/static ./
Maybe I’ve changed some files in here too… and now everything is great… so now git doesn’t know what happend? How he could trace a movement of files without notifying it like mercurial does with addremove.
For example now with mercurial I could do:
hg addremove --similarity 80%
that’s it – mercurial traced where files was moved by recognizing files content, and I saved my files history.
one lad in here have some trick for this:
git add .
git ls-files --deleted | xargs git rm
but it’s like in CVS back then. you deleting files, you adding files. what about saving history of files??
Basically, git always automatically does something sort of like “addremove” when it applies a commit to update the working tree: it looks at added and removed files in the commit and detects pairs of added and removed files that are probably renames (using a “amount of change” heuristic). So you don’t have to use a special command; just do the adds and the removes, and git will later figure things out on its own.
In your example scenario, just tell git about the new files:
git add staticand about the deleted files:git add -u static, and you’re ready to commit. If you do agit statusbefore committing, you can see that it’s already detected the rename.[As another answer mentioned,
git add -Ais a nice shortcut that just adds everything in the working tree, including new and deleted files; the only reason to use the narrower commands above is if you want to avoid adding some other changes that happen to be in the working tree.]