假设您有一个版本号在两个分支中增加的文件,如何防止 Git 静默自动合并定义版本的两行更改行?
* Git automatically merges here, but shouldn't
|\
| * change same line to the same new text
* | change some line here
\|
* prior history/root commit
在我们的例子中,我们有一个支持迁移的数据库模式。我们的主模式文件定义了当前的模式版本。如果两个人更改架构,例如在不同的表中添加一个数据库列,并且都将架构版本增加+1 , Git 会默默地合并所有内容,但结果会被破坏。
我建议在任何行上添加一个特殊标记,以使 Git 不会自动合并此特定行。有没有像这样的功能我不知道或如何实现?
这是一个 shell 命令列表,用于创建一个说明问题的示例 Git 历史记录:
$ git init test
Initialized empty Git repository in $PWD/test/.git/
$ cd test/
$ echo "version 1" > file
$ git add file
$ git commit -m "add file v1"
[master (root-commit) 4ef6950] add file v1
1 file changed, 1 insertion(+)
create mode 100644 file
$ git checkout -b a
Switched to a new branch 'a'
$ echo "version 2" > file
$ git commit -a -m "bump to v2"
[a 85dba39] bump to v2
1 file changed, 1 insertion(+), 1 deletion(-)
$ git checkout -b b master
Switched to a new branch 'b'
$ echo "version 2" > file
$ git commit -a -m "bump to v2 in b"
[b b0fcf46] bump to v2 in b
1 file changed, 1 insertion(+), 1 deletion(-)
$ git merge a
Merge made by the 'recursive' strategy.
$ git status # shouldn't be clean
On branch b
nothing to commit, working directory clean