我正在使用 github 在本地机器上创建我的最新版本代码的副本,我不想发出推送请求我只想发出 pull 请求并修改我本地机器上的一些文件然后尝试告诉 github 忽略一些文件并更新其他文件。
我使用以下命令忽略名为“config.inc.php”的文件:
git rm /home/escogit/www/inc/config.inc.php
然后我对远程 github 存储库中的其他文件进行了更改,当我尝试使用命令“git pull”获取新更改时,出现以下错误:
remote: Counting objects: 9, done. remote: Compressing objects: 100% (1/1), done. remote: Total 5 (delta 4), reused 5 (delta 4) Unpacking objects: 100% (5/5), done. From github.com:Visooal/Colegios e724ba3..a624059 master -> origin/master Updating e724ba3..a624059 error: Your local changes to the following files would be overwritten by merge: www/inc/config.inc.php Please, commit your changes or stash them before you can merge. Aborting
注意:即使我使用命令 git commit -m ".config.inc.php ignored"提交,我也会收到该错误
最佳答案
首先,git rm
不会忽略文件。它从本地和索引中删除文件。如果您在删除文件之前提交了文件,它将始终在您的树中,即使它不在当前索引中也是如此。另一个人可以很容易地不小心重新添加它。在 git rm
之后,您应该为该文件设置一个 .gitignore 条目。人们仍然可以手动绕过 .gitignore,但该文件不会再显示在 git status
或任何 UI 工具中。
你需要按照它说的去做。 git commit -a -m "My Commit Comment"
在你做 git pull
为了提供更清晰的画面,假设您已经git rm
编辑了该文件,请运行这些命令。
echo 'config.inc.php' > .gitignore
git add .gitignore
git commit -a -m "Removed uneeded file"
git pull
// Fix any merge issues
git commit -a -m "Merge"
git push
关于git - 我怎样才能将一些文件忽略到与 github 同步的本地存储库中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10098013/