Git rm——缓存后仍被跟踪?
我的本地文件系统中有文件和文件夹,比如settings.py和migrations/folder,我不想再跟踪它们了。当我在远程服务器上推送代码时,它们第一次被跟踪 我想要的是:当我在远程服务器上运行git pull时,我只更新跟踪的代码,并让settings.py和migrations/folder退出更新 以下是我所做的: 在我的本地文件系统上 首先,Git rm——缓存后仍被跟踪?,git,Git,我的本地文件系统中有文件和文件夹,比如settings.py和migrations/folder,我不想再跟踪它们了。当我在远程服务器上推送代码时,它们第一次被跟踪 我想要的是:当我在远程服务器上运行git pull时,我只更新跟踪的代码,并让settings.py和migrations/folder退出更新 以下是我所做的: 在我的本地文件系统上 首先, I added `myapp/settings.py` and `migrations/` in my .gitignore file.
I added `myapp/settings.py` and `migrations/` in my .gitignore file.
那么
settings.py文件和migrations文件夹已成功从my GitHub repo中删除
我的问题:在修改settings.py和migrations文件夹时,我在远程服务器上运行git pull时,似乎settings.py和migrations文件夹仍在跟踪中:
$me@server git pull origin master
....
error: Your local changes to the following files would be overwritten by merge:
migrations/0001_initial.py
myapp/settings.py
Please, commit your changes or stash them before you can merge.
Aborting
我希望服务器忽略这些更改,因为我没有从repo中跟踪它们
另一个有用的信息是:
我不知道这是否有帮助,但我不想将更改从远程提交到GitHub repo,我只想从GitHub repo中提取更改,因为“正确”代码必须来自本地repo,但settings.py和migrations文件夹在远程上不同。
因此,如果这有什么帮助的话,下面是我的远程服务器上git状态的结果:
# On branch master
# Your branch is behind 'origin/master' by 5 commits, and can be fast-forwarded.
#
# Changes not staged for commit:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: catalog/migrations/0004_auto_20150115_1214.pyc
# deleted: catalog/migrations/0005_auto_20150116_0855.py
# deleted: catalog/migrations/0005_auto_20150116_0855.pyc
# deleted: catalog/migrations/0006_auto_20150119_1153.py
# modified: myapp/settings.py
#
非常感谢你的帮助 删除文件后,执行git添加。
这可能会再次添加文件,除非您已将其添加到您的中。删除文件后,请执行git添加。
这可能会再次添加文件,除非您已将其添加到您的解决方案中。我没有测试副本提供的解决方案,但如果相同的问题再次出现,我会进行测试,因为我已经做了一些事情来解决我的问题:
我只是删除了远程存储库,并在远程上再次进行了git克隆,现在,此远程存储库的行为与预期一致。我没有测试副本提供的解决方案,但肯定会测试相同的问题是否再次出现,因为我已经做了一些事情来解决我的问题:
我只是删除了远程存储库,并在远程上再次进行了git克隆,现在,此远程存储库的行为符合预期。感谢您的回答。我想取消跟踪的文件被放在我的.gitignore文件中,但这并没有解决我的问题。但你是对的,值得注意的是,我会更新我的问题。一旦跟踪到文件,git rm不会取消跟踪,它只会将删除记录为更改。gitignore会阻止将文件添加到被跟踪的文件列表中,但不会阻止已被跟踪的文件继续被跟踪。谢谢您的回答。我想取消跟踪的文件被放在我的.gitignore文件中,但这并没有解决我的问题。但你是对的,值得注意的是,我会更新我的问题。一旦跟踪到文件,git rm不会取消跟踪,它只会将删除记录为更改。gitignore会阻止将文件添加到被跟踪的文件列表中,但不会阻止已被跟踪的文件继续被跟踪。的可能重复
# On branch master
# Your branch is behind 'origin/master' by 5 commits, and can be fast-forwarded.
#
# Changes not staged for commit:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: catalog/migrations/0004_auto_20150115_1214.pyc
# deleted: catalog/migrations/0005_auto_20150116_0855.py
# deleted: catalog/migrations/0005_auto_20150116_0855.pyc
# deleted: catalog/migrations/0006_auto_20150119_1153.py
# modified: myapp/settings.py
#