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 static
and about the deleted files: git add -u static
, and you're ready to commit. If you do a git status
before committing, you can see that it's already detected the rename.
[As another answer mentioned, git add -A
is 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.]
Git doesn't track renames via additional metadata so you can just do git add -A
with the full assurance that you aren't missing any metadata.
While Git tracks "whole tree" history rather than file history, you can activate its rename and copy detection after the fact with commands like git log -M -C
and git log --follow <file>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With