在我的本地存储库中,我有一个修改过的设置文件,其中包含存储在GitHub上的不同版本的文件。每当我从GitHub进入我的本地存储库时,我的本地副本就会被更改。
有没有办法避免让我的本地副本被 git-pull 覆盖?
答案 0 :(得分:1)
虽然您可以做一些花哨的步法来获取分支并仅检出特定文件,但出于实际目的, 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
答案 1 :(得分:0)
这就是gitignore的用途 - 以及Google。
答案 2 :(得分:0)
您需要将设置文件添加到.gitignore。 在此link
了解详情