在我的本地存储库中,我有一个修改后的设置文件,该文件的不同版本存储在 GitHub 上。每当我从 GitHub 拉入本地存储库时,我的本地副本都会更改。
有什么办法可以避免我的本地副本被git-pull覆盖?
虽然您可以做一些花哨的工作来获取分支并仅检查特定文件,但出于实际目的,git-pull将合并提交清单中的所有文件。所以,你需要改变你的工作流程。
如果您需要将文件存储在存储库中,但又不想覆盖本地更改,那么正确的做法是创建一个示例文件,并使用您的 .gitignore 文件来避免将文件的本地副本提交回存储库。例如:
# Move the repository-managed copy of the example file,
# then add the related local filename to your repository's
# .gitignore file.
git mv .rcfile rcfile.example
echo '.rcfile' >> .gitignore
# Commit the necessary files.
git add .gitignore
git commit -m 'Add example file.'
# Copy the repository-managed example to your local file,
# which will not be overwritten on future pulls.
cp rcfile.example .rcfile
这就是gitignore的用途——还有谷歌。
您需要将设置文件添加到 .gitignore 。在此链接上阅读更多内容