防止在主分支上合并某种文件 - Git [英] Prevent merge on master branch for a type of file - Git
问题描述
我有一个发行版分支(主)和一些其他分支用于开发目的的git回购。
作为一个嵌入式项目,每个编译都会生成或修改一些.tbl文件。我需要保持主分支中的tbl文件不被修改(除非有新版本),因此不要与其他分支合并来修改这些tbl文件。
I已经尝试将tbl文件声明为二进制文件或者使用 *。tbl merge = ours
但按照 https://git-scm.com/docs/git-merge 这仅适用于发生冲突的情况。
有没有人遇到类似的情况?
您可以设置 *。tbl merge =我们的
位于 .gitattributes
文件,
并添加了全局设置:
git config --global merge.ours.driver true
它只保留 *。tbl
文件在 master
分支上的部分情况的版本(前两种情况如下)。
将其他分支合并到 master
时,那里对于 *。tbl
文件有三种情况:
*。tbl
文件:表示其他版本的 *。tbl
文件分支与 master
分支中的版本不同。既然你已经为我们的 *。tbl
设置了合并策略。然后, master
分支上的 *。tbl
版本将会是ketp。
*。tbl
文件的双方:,表示 *。tbl
file
master
其他分支是相同的,所以不要担心 *。tbl
文件 master
分支被覆盖。 改变 *。tbl
文件只在其他分支端:这将覆盖 *。tbl
文件与其他分支的版本,因为git merge使用递归合并战略。因此,您需要将 *。tbl
文件与 master
分支上的版本切换。所以你可以使用下面的命令:
git merge branchname
git checkout HEAD〜* .tbl
git提交-m'将文件切换为主文件上的版本'
顺便说一句,如果 *。tbl
文件对非主分支上的版本控制不是必需的,那么您只能管理 master
分支。
或者您可以参考另一个选项:管理文件 *。tbl
在单独的分支中(例如 tbl
分支)。
即使 *。tbl
文件可能会覆盖 master
分支,版本在 tbl
分支上应该是正确的。当你需要一个新版本时,你可以从 tbl
分支签出版本到 master
分支:
git checkout master
git checkout tbl * .tbl
git commit -m'将版本恢复为最新版本'
然后您就可以为新版本做准备了。
在 master
分支上发布后,您可以更新 tbl
分支上的文件:
git checkout tbl
git checkout master * .tbl
git commit -m'用tbl分支上的新版本更新文件'
I have a git repo with a release branch ("master") and some other branches for develop purposes.
Being an embedded project, there are some .tbl files which are generated or modified on every compilation. I need to keep the tbl files in the master branch not modified (unless there is a new release) and therefore prevent merging with other branches from modifying those tbl files.
I already tried declaring tbl files as binary or using *.tbl merge=ours
but as specified in https://git-scm.com/docs/git-merge this only work in case of conflict.
Has anyone ever run across a similar situation?
You can set *.tbl merge=ours
in .gitattributes
file,
and add global setting:
git config --global merge.ours.driver true
It only keep the version of *.tbl
file on master
branch for part of situations (as the first two situations as below).
When you merge other branches into master
, there has three situations for the *.tbl
file:
- Has conflict for the
*.tbl
file when merging: that means the version of*.tbl
file in other branches is different from the version inmaster
branch. Since you have set merge strategies for the*.tbl
as ours. Then the version of*.tbl
onmaster
branch will be ketp. - Did not change the
*.tbl
file on both sides: that means both the versions of*.tbl
file onmaster
the other branches are same, so don’t worry the*.tbl
file onmaster
branch is overwritten. Change the
*.tbl
file only on other branches side: this will overwrite the*.tbl
file with the version of the other branches since git merge use the recursive merge strategy. So you need to switch*.tbl
file with the version onmaster
branch. So you can use below commands:git merge branchname git checkout HEAD~ *.tbl git commit -m 'switch the file as the version on master'
BTW, if the *.tbl
file is not necessary to version control on non-master branches, you can only manage the file on master
branch.
Or there is another option you can refer: manage the file *.tbl
in a separate branch (such tbl
branch).
Even the *.tbl
file may be overwritten on master
branch, the version on tbl
branch should be correct. When you need a new release, you can checkout the version from tbl
branch to master
branch:
git checkout master
git checkout tbl *.tbl
git commit -m 'recovery the version as last release'
Then you can prepare for the new release.
After releasing on master
branch you can update the file on tbl
branch:
git checkout tbl
git checkout master *.tbl
git commit -m 'update the file with new release version on tbl branch'
这篇关于防止在主分支上合并某种文件 - Git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!