几个评论:
然后将您的分支合并到master
.
忽略 rebase 的所有上下文通常不是一个好主意,但如果你确定你的修改(如“修改根本不需要上下文”),它会起作用。
从git rebase 手册页:
-C<n>
<n>
确保每次更改前后至少有几行周围的上下文匹配。
当周围上下文的行数较少时,它们都必须匹配。
默认情况下,不会忽略任何上下文。
您可以很容易地对其进行测试(在 PowerShell 会话中,在 Xp 上使用 Git1.6.5.1)
首先创建一个小蝙蝠实用程序genfile.bat
echo hello, World %1 > afile.txt
echo hello, World %2 >> afile.txt
echo hello, World 3 >> afile.txt
echo hello, World 4 >> afile.txt
echo hello, World 5 >> afile.txt
然后创建一个 repo 并添加一个文件:
PS D:\git\tests\mergeLines> git init m0
PS D:\git\tests\mergeLines> cd m0
PS D:\[...]\m0> D:\git\tests\mergeLines\genfile.bat 1 2
PS D:\[...]\m0> git add -A
PS D:\[...]\m0> git ci -m "afile to be modified concurrently"
您的文件如下所示:
hello, World 1
hello, World 2
hello, World 3
hello, World 4
hello, World 5
在分支中修改
PS D:\[...]\m0> git co -b abranch
PS D:\[...]\m0> D:\git\tests\mergeLines\genfile.bat 1 2_modified
PS D:\[...]\m0> git ci -a -m "afile modified in abranch"
你将会有:
hello, World 1
hello, World 2_modified
hello, World 3
hello, World 4
hello, World 5
然后在master中修改
PS D:\[...]\m0> git co master
PS D:\[...]\m0> D:\git\tests\mergeLines\genfile.bat 1_master 2
PS D:\[...]\m0> git ci -a -m "afile modified in master"
这给了你:
hello, World 1_master
hello, World 2
hello, World 3
hello, World 4
hello, World 5
克隆该回购以进行第一次实验(即:合并abranch
into master
)
PS D:\[...]\m0> cd ..
PS D:\git\tests\mergeLines> git clone m0 m1
PS D:\git\tests\mergeLines> cd m1
PS D:\[...]\m1> git co -b abranch origin/abranch
PS D:\[...]\m1> git co master
PS D:\[...]\m1> git merge abranch
这给你一个冲突:
Auto-merging afile.txt
CONFLICT (content): Merge conflict in afile.txt
Automatic merge failed; fix conflicts and then commit the result.
PS D:\[...]\m1> type afile.txt
<<<<<<< HEAD
hello, World 1_master
hello, World 2
=======
hello, World 1
hello, World 2_modified
>>>>>>> abranch
hello, World 3
hello, World 4
hello, World 5
再次克隆第一个 repo,这一次首先abranch
在 之上rebase master
,没有上下文:
PS D:\[...]\m1> cd ..
PS D:\git\tests\mergeLines> git clone m0 m2
PS D:\git\tests\mergeLines> cd m2
PS D:\[...]\m2> git co -b abranch origin/abranch
PS D:\[...]\m2> git rebase -C0 master
您的文件被静默合并:
hello, World 1_master
hello, World 2_modified
hello, World 3
hello, World 4
hello, World 5
当然,如果您切换回master
并现在合并abranch
,结果将是快进合并。
PS D:\git\tests\mergeLines\m2> git co master
Switched to branch 'master'
PS D:\git\tests\mergeLines\m2> git merge abranch
Updating c8f48b4..8bee1d2
Fast forward
afile.txt | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)