最近开始使用 git ...刚刚注意到我的文件的克隆带有 ' 〜' 附加在最后......为什么会发生这种情况
我使用 git 在我的存储库中提交更改,
按照以下步骤操作
git add .
git commit -m "message"
,但注意到存储库中也存在进行更改的文件的克隆 新文件末尾附加了“~
”符号。
为什么会发生这种情况? 将来我该如何预防?
另外,关于如何用“~”删除文件的一些想法也很好,
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的编辑器正在生成 FILENAME~ 形式的备份文件。 (Emacs 会这样做;否则可以说服它。)您没有要求 git 忽略以 ~ 结尾的文件。 使用 git add . ,您可以告诉 git 添加您未要求其忽略的所有内容。
也可以看看:
gitignore
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的答案,在工作目录中添加一个
.gitignore
文件,例如:必须添加并提交该 .gitignore 文件才能通过“
git clone”持久保存>',因为有几个级别'gitignore'。
To complete bendin's answer, add in your working directory a
.gitignore
file with for instance:That .gitignore file will have to be added and committed in order to persist through '
git clone
', since there are several levels of 'gitignore'.使用 gitignore,您可以忽略尚未跟踪的文件,但如果您添加了一个文件,然后在 .gitignore 中将其匹配,它仍然会被标记为内容更改时更新。
因此,从将来的提交中删除它的方法是使用:
另一方面,如果您想从旧提交中删除临时文件,您应该查看 git 过滤器分支。 如果您已经发布了存储库,请务必小心,因为此命令会重写历史记录,因此请备份您的存储库,并在选择这种方式时了解您正在做什么。
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:
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.