【问题标题】:How to avoid merging a specific file with git-pull?如何避免将特定文件与 git-pull 合并?
【发布时间】:2012-12-09 07:03:12
【问题描述】:

在我的本地存储库中,我有一个修改后的设置文件,该文件的不同版本存储在 GitHub 上。每当我从 GitHub 拉取到本地存储库时,我的本地副本都会更改。

有什么方法可以避免我的本地副本被 git-pull 覆盖?

【问题讨论】:

  • 投反对票的人想给出理由吗?这似乎是一个不错的问题...
  • 这表明根本没有研究工作。既没有阅读任何教程,也没有使用谷歌。 @AbeMiessler

标签: git github gitignore git-pull


【解决方案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

【讨论】:

    【解决方案2】:

    您需要将设置文件添加到 .gitignore 。 阅读更多内容link

    【讨论】:

      【解决方案3】:

      这就是 gitignore 的用途 -- 和 Google。

      【讨论】:

      • 非常感谢您,否决投票者先生。在发布前两个答案后,提问者改变了他的问题,所以 gitignore 的事情自然不再准确了。
      猜你喜欢
      • 2015-07-15
      • 1970-01-01
      • 2022-01-06
      • 2019-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      相关资源
      最近更新 更多