1

I used git to commit changes in my repository,

followed these steps

git add .
git commit -m "message"

but noticed a clone of the file where changes were made also present in the repository new file had '~' symbol appended at the end.

why did this happen ? And how can I prevent it in the future ?
Also some thoughts on how to remove the file with "~" would be great

Thanks

bendin
  • 9,424
  • 1
  • 39
  • 37
Vic
  • 336
  • 6
  • 18

3 Answers3

8

Your editor is generating backup files of the form FILENAME~. (Emacs does this; it can be persuaded otherwise.) You have not asked git to ignore files ending in ~. With git add . you're telling git to add everything that you haven't asked it to ignore.

See also: gitignore

bendin
  • 9,424
  • 1
  • 39
  • 37
8

To complete bendin's answer, add in your working directory a .gitignore file with for instance:

*~
*.bak
*.old

That .gitignore file will have to be added and committed in order to persist through 'git clone', since there are several levels of 'gitignore'.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

Also some thoughts on how to remove the file with "~" would be great

With gitignore you ignore files that are not yet being tracked, but if you added a file, and later matched it in your .gitignore, it will still be marked as updated when it content changes.

So, the way to remove it from future commits, is using:

git rm *~

In the other hand, if you want to remove the temp files from old commits, you should look at git filter-branch. Be careful if you've published your repo, as this commands rewrites the history, so backup your repo and be aware of what you're doing if you choose this way.

Doppelganger
  • 20,114
  • 8
  • 31
  • 29