Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming files in git

Tags:

git

I have two files checked into GitHub:

  1. index.html
  2. backup.html

Now I want to rename backup.html into index.html and vice versa. I don't really care about maintaining the change history for each file. How do I do this in Git?

like image 863
Frankie Ribery Avatar asked Apr 08 '11 09:04

Frankie Ribery


3 Answers

This will contain the history:

git mv backup.html backup2.html
git mv index.html backup.html
git mv backup2.html index.html

Without history just rename the file to your liking on your file system.

like image 52
tom Avatar answered Oct 22 '22 19:10

tom


You don't have to do anything special as you are not adding any new paths to be tracked.

You can just move the files around and use git add to update their contents.

mv index.html tmpname
mv backup.html index.html
mv tmpname backup.html

then:

git add index.html backup.html

or:

git add -u

or:

git commit -a -m "swap backup.html and index.html"
like image 31
CB Bailey Avatar answered Oct 22 '22 19:10

CB Bailey


Use git mv and move the first file to a temporary name, then the second to the first and finally the temporary file to the second.

like image 24
hammar Avatar answered Oct 22 '22 19:10

hammar