使用 git 时必须遵循的具体程序是什么?我将给出我的程序(不知何故,它工作得不太顺利):
- cloned a repository: (works fine)
- added settings files to .gitignore to prevent overwriting the originial
settingfiles on the remote (= test environment)
- made changes to my local repository and committed it locally (works fine)
- pushed it from local to remote (did not work properly)
当推送到远程时,远程上的设置文件被删除,这导致我的测试环境崩溃。我只是希望如果我推送而不是删除设置文件,它们会被忽略。
我做错了什么/忘记了什么?有任何想法吗?
据我了解,设置文件已经在您克隆的 git 存储库中进行了跟踪。这意味着即使您将其添加到.gitignore
,仍将被跟踪。
要从历史记录中删除该文件,并确保将来它被忽略,您应该
- 将其添加到
.gitignore
(就像你已经做的那样)
- run
git filter-branch --index-filter 'git rm --cached --ignore-unmatch settingsfile' HEAD
请注意,您需要为该文件所在的每个分支运行上述命令。
那么你需要git push -f origin master
(if master
是分支的名称,并且origin
遥控器的名称)
你可以参考本指南 http://help.github.com/removing-sensitive-data/获取更多信息。
另外,正如 Rafid K. Abdullah 所说,您还没有删除任何内容(如果您遵循了您在帖子中描述的工作流程);您刚刚添加了可以轻松恢复的修改。毕竟这就是 git 的用途:)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)