将变基结果拉入合并冲突后
pull after rebase results into merging conflicts
我有一个分支 B,它已在另一个仓库中检出,然后在那里进行了一些更改,并在变基后使用 --force 推送它们(这是对上次提交的修正)。
现在,如果我将更改后的分支拉入第一个 repo,我会遇到合并冲突。
我运行的命令(有不相关的改动,简化了实际输出)如下:
# First checkout the original B
$ pwd
/home/user/dir1
$ git checkout B
Switched to branch 'B'
Your branch is up-to-date with 'origin/B'.
# Now clone the same repo into another directory and checkout B there
$ cd .. && git clone git clone ssh://git@myhost/myrepo.git dir2 && cd dir2
$ git checkout B
Switched to branch 'B'
Your branch is up-to-date with 'origin/B'.
# Now edit some file, commit it and "merge" the changes
# to the originally last commit as a fixup
$ nano file.txt
$ git commit -a -m "Fixup to file.txt"
$ git rebase -i HEAD~2
... the last commit is "fixup'ed" to the last commit in the original branch (the commit before "Fixup to the file.txt" commit
# Push the B with rewritten history to the upstream
$ git push --force origin B
# Get back to the original repo and pull the changes
$ cd ../dir1
$ git pull origin B
...
CONFLICT (content): Merge conflict in .../file.txt
...
分支的两个副本之间的唯一区别在于 "top" 提交。
是否可以告诉 git,我想用我在上游中的内容替换第一个 repo 中的最后一次提交,而无需 git-pull 尝试查看相应文件中的更改?
有这样的历史
...-A-B-C-D-E # HEAD
其中 E
是 dir/
中未更改的提交。我们将引入 E'
作为起源于 E
但从 dir2
.
重新建立基础并强制推送的提交
在 dir
中,您可以将 HEAD
倒回到之前的提交中:
git reset --hard HEAD^
获得
...-A-B-C-D # HEAD
\
`-E # dangling and invisible, will be garbage collected
之后
git pull upstream B
那里有什么都会给你
...-A-B-C-D-E' # HEAD
\
`-E # dangling and invisible, will be garbage collected
请注意,您将丢失 E
的内容(除非您在 reflog
中搜索它)
我有一个分支 B,它已在另一个仓库中检出,然后在那里进行了一些更改,并在变基后使用 --force 推送它们(这是对上次提交的修正)。 现在,如果我将更改后的分支拉入第一个 repo,我会遇到合并冲突。
我运行的命令(有不相关的改动,简化了实际输出)如下:
# First checkout the original B
$ pwd
/home/user/dir1
$ git checkout B
Switched to branch 'B'
Your branch is up-to-date with 'origin/B'.
# Now clone the same repo into another directory and checkout B there
$ cd .. && git clone git clone ssh://git@myhost/myrepo.git dir2 && cd dir2
$ git checkout B
Switched to branch 'B'
Your branch is up-to-date with 'origin/B'.
# Now edit some file, commit it and "merge" the changes
# to the originally last commit as a fixup
$ nano file.txt
$ git commit -a -m "Fixup to file.txt"
$ git rebase -i HEAD~2
... the last commit is "fixup'ed" to the last commit in the original branch (the commit before "Fixup to the file.txt" commit
# Push the B with rewritten history to the upstream
$ git push --force origin B
# Get back to the original repo and pull the changes
$ cd ../dir1
$ git pull origin B
...
CONFLICT (content): Merge conflict in .../file.txt
...
分支的两个副本之间的唯一区别在于 "top" 提交。 是否可以告诉 git,我想用我在上游中的内容替换第一个 repo 中的最后一次提交,而无需 git-pull 尝试查看相应文件中的更改?
有这样的历史
...-A-B-C-D-E # HEAD
其中 E
是 dir/
中未更改的提交。我们将引入 E'
作为起源于 E
但从 dir2
.
在 dir
中,您可以将 HEAD
倒回到之前的提交中:
git reset --hard HEAD^
获得
...-A-B-C-D # HEAD
\
`-E # dangling and invisible, will be garbage collected
之后
git pull upstream B
那里有什么都会给你
...-A-B-C-D-E' # HEAD
\
`-E # dangling and invisible, will be garbage collected
请注意,您将丢失 E
的内容(除非您在 reflog
中搜索它)