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

强颜欢笑 提交于 2019-12-24 08:26:10

问题


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


回答1:


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




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/801840/started-using-git-recently-just-noticed-clones-of-my-files-with-append

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!