在我的GitHub回购中,我有一个文件www / settings.js,这是存储自定义设置的地方。我将此文件添加到.gitignore但尝试在本地存储库上提交更改时仍然出现错误:
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
(use "git pull" to update your local branch)
Changes not staged for commit:
modified: www/index.html
modified: www/settings.js
no changes added to commit
如何阻止git尝试在本地更新www / settings.js?
答案 0 :(得分:1)
这意味着此文件已经提交到您的仓库,您将需要:
在任何一种情况下,您都需要在继续之前备份另一个位置的文件内容。以下是每个案例的说明:
cp www/settings.py www/settings.py.backup
git filter-branch --index-filter 'git rm --cached --ignore-unmatch www/settings.js' HEAD
# Copy the original file back
mv www/settings.py.backup www/settings.py
这将从您对回购的任何提交中删除文件的所有痕迹。
cp www/settings.py www/settings.py.backup
git rm --cached www/settings.py
# Commit the change
git ci
# Copy the original file back
mv www/settings.py.backup www/settings.py
答案 1 :(得分:0)
除了忽略.gitignore中的文件外,您应该将其从存储库中删除并保留其本地副本:
git rm --cached www/settings.js
git commit -m 'do not track changes to local settings'
git push