为了账号安全,请及时绑定邮箱和手机立即绑定

git rebase,跟踪'本地'和'远程'

git rebase,跟踪'本地'和'远程'

萧十郎 2019-08-15 14:44:41
git rebase,跟踪'本地'和'远程'在进行git rebase时,我常常难以解决在解决冲突时“本地”和“远程”发生的事情。我有时会产生这样的印象:他们将一方提交交换到另一方提交。这可能(肯定)因为我还没有正确理解。变基础时,谁是'本地',谁是'偏远'?(我使用P4Merge解决冲突)
查看完整描述

3 回答

?
神不在的星期二

TA贡献1963条经验 获得超6个赞

底线

git rebase

  • LOCAL =你在基础重建的基础

  • REMOTE =承诺你正在向上移动

git merge

  • LOCAL =您要合并的原始分支

  • REMOTE =你正在合并的另一个分支

换句话说,LOCAL始终是原始版本,而REMOTE总是那些之前没有提交过的人,因为它们被合并或重新定位在顶层

证明给我看!

当然。不要相信我的话!这是一个简单的实验,您可以自己查看。

首先,确保正确配置了git mergetool。(如果你没有,你可能无论如何都不会阅读这个问题。)然后找一个可以使用的目录。

设置您的存储库:

md LocalRemoteTestcd LocalRemoteTest

创建初始提交(使用空文件):

git initnotepad file.txt  (use the text editor of your choice)
  (save the file as an empty file)git add -Agit commit -m "Initial commit."

在非master的分支上创建提交:

git checkout -b notmasternotepad file.txt
  (add the text: notmaster)
  (save and exit)git commit -a -m "Add notmaster text."

在主分支上创建提交:

git checkout masternotepad file.txt
  (add the text: master)
  (save and exit)git commit -a -m "Add master text."gitk --all

此时,您的存储库应如下所示:

现在进行rebase测试:

git checkout notmastergit rebase master
  (you'll get a conflict message)git mergetool
  LOCAL: master
  REMOTE: notmaster

现在进行合并测试。关闭mergetool而不保存任何更改,然后取消rebase:

git rebase --abort

然后:

git checkout mastergit merge notmastergit mergetool
  LOCAL: master
  REMOTE: notmastergit reset --hard  (cancels the merge)

您的结果应与顶部显示的结果相同。


查看完整回答
反对 回复 2019-08-15
?
临摹微笑

TA贡献1982条经验 获得超2个赞

我没有完全解决您的问题,但我认为下图解决了您的问题。(Rebase:远程存储库--->工作区)

来源:我的Git工作流程


查看完整回答
反对 回复 2019-08-15
  • 3 回答
  • 0 关注
  • 1316 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信