0

I committed some changes to my project, and one of the things done was the movement of a file into another folder. I did the usual:

git add .
git commit -m "commit something"
git push origin

But on my github account, when looking at the project, the file I moved is still in the location before the movement. The file is also in the folder I moved it to. When looking at where it was moved, there is no commit info which I would think should happen, but there is on the old one. Is there a reason why this is? I am sorry if that is not very clear, please let me know if it needs to be made clearer.

Andy
  • 10,553
  • 21
  • 75
  • 125

2 Answers2

2

When you move or rename a file, the old file reference is still there. You need to remove the file from git by...

git rm filename

And then commit.

Kumar Bibek
  • 9,016
  • 2
  • 39
  • 68
  • What happens if I already deleted it and its not in my local git repo? How do I remove it from github to reflect that its also missing locally? – Andy May 03 '12 at 06:49
  • The same way. You can run this command, and see that git will remove this file. – Kumar Bibek May 03 '12 at 06:49
  • I did, but its not reflected on github. It definitely removed it locally now for sure. But I can't push that change. DO I have to make a more significant change or something? – Andy May 03 '12 at 06:54
  • Nope, I was just being dumb. I didn't commit it apparently. At least not correctly. You have been most helpful. Is there another way that I can just remove files without telling github directly, and have it include it automatically as well as moving them? Thanks for the help though! – Andy May 03 '12 at 07:12
  • Well as far as I know, this is the only way. And it makes sense also, to manually ask git to remove a file, if it has been removed or renamed. You could try and check for other ways. – Kumar Bibek May 03 '12 at 07:41
1

There is git mv old new; you use it like the normal mv command. If you already added the new file, remove the old one from git: git rm old

It's basically just sugar for the following commands:

mv old new
git add new
git rm old

Also have a look at What's the purpose of git-mv? for more information.

Community
  • 1
  • 1
ThiefMaster
  • 310,957
  • 84
  • 592
  • 636