gpt4 book ai didi

git - 如何避免将特定文件与 git-pull merge ?

转载 作者:太空狗 更新时间:2023-10-29 13:26:42 25 4
gpt4 key购买 nike

在我的本地存储库中,我有一个修改后的设置文件,其中包含存储在 GitHub 上的文件的不同版本。每当我从 GitHub pull 到我的本地存储库时,我的本地副本就会发生变化。

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

最佳答案

你不能 pull 部分提交

虽然您可以做一些花哨的步法来获取分支并仅 check out 特定文件,但出于实用目的,git-pull 将 merge 提交 list 中的所有文件。因此,您需要改变您的工作流程。

使用示例文件的正确工作流程

如果您需要在存储库中存储一些文件,但不想覆盖本地更改,正确的做法是创建一个示例文件,并使用您的 .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

关于git - 如何避免将特定文件与 git-pull merge ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13994546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com