tags:

views:

163

answers:

3

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

+7  A: 

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
Good answer. +1
VonC
i think emacs uses another form also wich is #filename#
Nuno Furtado
+7  A: 

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'.

VonC
A: 

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