jjzjj

git 工作流 : Can I prevent a certain file from being merged to another branch but still keep it under version control?

coder 2023-06-23 原文

我有一个包含两个分支的存储库:live 和 stage。存储库包含基于 Web 的应用程序的代码。我想为 stage 和 live 分支维护两个不同的 .htaccess 文件,但仍然对它们进行版本控制,因为为 stage 站点提供服务的性质有点不同(例如,现在我希望对缓存进行定时不同)。

我是 git 的新手,所以可能有一个简单的解释,但我想要一个工作流,当我在现场时,我 pull 了更改(简单的 git merge stage) , 我没有覆盖 live 分支中现有的 .htaccess 。有没有办法配置这个?我是否遗漏了 git 中的一些重要概念?

同样,还有一大块(但可能很多).html 文件,我想在其中跟踪更改但不将它们 merge 回实时。需要明确的是,我希望 live 和 stage 能够跟踪这些文件中的更改,但知道在进行 merge 时不要 merge 那些特定的更改。

最佳答案

我找到了一个 answer on another question在 Stack Overflow 上,归功于 fcurella:

Let's say you want to exclude the file config.php

On branch A:

  1. Create a file named .gitattributes in the same dir, with this line: config.php merge=ours. This tells git what strategy to use when merging the file. In this case it always keep your version, ie. the version on the branch you are merging into.

  2. Add the .gitattributes file and commit

On branch B: repeat steps 1-2

Try merging now. Your file should be left untouched.

这似乎是一个更具扩展性的解决方案。

关于git 工作流 : Can I prevent a certain file from being merged to another branch but still keep it under version control?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4515679/

有关git 工作流 : Can I prevent a certain file from being merged to another branch but still keep it under version control?的更多相关文章

随机推荐