Vic
Vic

Reputation: 306

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

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

Upvotes: 1

Views: 499

Answers (3)

Doppelganger
Doppelganger

Reputation: 20815

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.

Upvotes: 0

VonC
VonC

Reputation: 1323653

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

Upvotes: 8

bendin
bendin

Reputation: 9574

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

Upvotes: 8

Related Questions