【发布时间】:2017-08-15 11:06:34
【问题描述】:
我在使用git rebase 的--keep-empty 选项时遇到了一些问题,我是
不知道我是否误解了这个选项的作用,或者有一个错误。
这是一个最小的例子:
设置
-
创建一个新的 Git 存储库和一个初始的、不相关的提交。
$ git init $ echo something >base.txt $ git add base.txt $ git commit -m 'some base commit to not run into the root corner case' -
创建一个添加两个新文件的新提交。
$ echo A >a.txt; echo B >b.txt $ git add a.txt b.txt $ git commit -m 'add A and B' -
修改其中一个文件。
$ echo A1 >a.txt $ git add a.txt $ git commit -m 'change A' -
修改其他文件。
$ echo B1 >b.txt $ git add b.txt $ git commit -m 'change B'
变基
$ git checkout -b rebased master
$ git rebase --keep-empty -i :/base
... 选择edit 添加A 和B 的提交,并将其更改为仅添加B(在实际情况下,原因可能是A 是机密的):
$ git rm a.txt
$ git commit --amend
$ git rebase --continue
当然,现在修改A 的下一次提交会产生冲突:
error: could not apply 182aaa1... change A
When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
Could not apply 182aaa1701ad100fc02a5d5500cacebdd317a24b... change A
…选择不添加修改版a.txt:
$ git mergetool
Merging:
a.txt
Deleted merge conflict for 'a.txt':
{local}: deleted
{remote}: modified file
Use (m)odified or (d)eleted file, or (a)bort? d
修改A 的提交现在为空:
$ git diff --cached
# nothing
… 并完成变基:
$ git rebase --continue
Successfully rebased and updated refs/heads/rebased.
问题
所以现在我有两个版本的历史记录,不同的是其中一个没有A 的踪迹。然而,因为我选择了--keep-empty 选项,我仍然希望rebased 中存在一个空提交,这表明A 会被修改,如果它在那里。
但显然情况并非如此:
$ git log --oneline master
f893569 change B
182aaa1 change A
3340b71 add A and B
38cb5da some base commit to not run into the root corner case
$ git log --oneline rebased
73a2c05 change B
55f502b add A and B
38cb5da some base commit to not run into the root corner case
这不是--keep-empty 应该做的,还是不起作用
正确吗?
相关:Rebase on the root and keep empty commits 是一个非常相似的问题,但它涉及我在这里明确避免的--root 极端情况。它没有答案,只有一些 cmets 表明我在这里展示的内容应该有效。另一个区别是,在另一个问题中,提交首先是空的,而这里只有在解决冲突后才变为空。
【问题讨论】:
标签: git git-rebase