Started using git recently … just noticed clones of my files with ' ~ ' appended in the end… why is this happening

StackOverflow https://stackoverflow.com/questions/801840

  •  03-07-2019
  •  | 
  •  

Question

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

Was it helpful?

Solution

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

OTHER TIPS

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top