I am renaming a file that I have earlier saved in my git repository. The status shows that one file has been added and another file has been removed. Do I need to remove and add to get the stat to commit correctly? If I don't add, will the repository save two images on the next commit, and then revert to a state with two images in the future (if I decide to revert back to the state I just committed ?)
Asked
Active
Viewed 31 times
1
-
You can use 'git mv' which will rename it http://stackoverflow.com/questions/2641146/handling-file-renames-in-git – Nick Apr 18 '14 at 18:34
-
possible duplicate of [Renaming a file without using rm in git](http://stackoverflow.com/questions/23160263/renaming-a-file-without-using-rm-in-git) – Nikhil Gupta Apr 18 '14 at 19:20
1 Answers
2
The correct way of moving a file under git is to use git to do it for you:
git mv old.txt new.txt
However, if you add the new file and remove the old one from git, you should get the same effect:
git add new.txt
git rm old.txt

Mureinik
- 297,002
- 52
- 306
- 350
-
is there a shortcut for moving several files (like mv items/* to old_items/*) – Hoytman Apr 18 '14 at 18:36
-
in git 1.7.0 and above you could `git mv items old_items`, where both the arguments are directories. – Mureinik Apr 18 '14 at 18:37