Sam*_*uel 14 git version-control history branch rebase
在我的git工作流中,我们有一个主存储库和一个分支master.每个人都从远程主人拉出来,每个人都推送到远程主人.我准备一个功能时,我想在自己的分支机构工作.到目前为止,我的历史是这样的:
git pull --rebase
git checkout -b new_feature
<make some commits>
git checkout master
git pull --rebase
Run Code Online (Sandbox Code Playgroud)
现在我想合并分支,这就是我需要的东西:
我最关心的是第3项,何时需要,以便我可以安全地推动变更.如果合并的提交与head之前的提交交织在一起,那么我将会遇到问题,看到我遇到的相关问题:git:推送单一提交,重新排序使用rebase,重复提交.
我读过以下内容:
而且我想我需要这样做:
git checkout master
git pull --rebase
git checkout new_feature
git rebase master
git checkout master
git rebase new_feature
git push
Run Code Online (Sandbox Code Playgroud)
我的理解是
git checkout new_feature
git rebase master
Run Code Online (Sandbox Code Playgroud)
将使new_feature看起来好像是从新的当前头部分支出来的.真的吗?然后
git checkout master
git rebase new_feature
Run Code Online (Sandbox Code Playgroud)
将new_feature置于主人之上.那是对的吗?如果是这样,这是我困惑的主要原因.如果"git rebase master"将master提交放在new_feature的底部,那么为什么"git rebase new_feature"将new_feature提交到master的顶部,即为什么不执行相反的操作呢?
Sha*_*tin 25
以下是您可以使用的工作流程,它可以满足您的需求.
git checkout master
git pull --rebase (1)
git checkout new_feature
<do a bunch of commits>
git rebase master (2)
git checkout master
git merge new_feature (3)
git branch -D new_feature (4)
Run Code Online (Sandbox Code Playgroud)
(1)git pull --rebase
将首先获取origin/master
然后重播您的本地master
.请注意,在示例日志中,您的本地提交位于"本地远程HEAD指针"之上.
> git log --oneline --all -10 --decorate
d34d34c (HEAD, master) Local commit message.
d3434r2 Local commit message.
d234d4c Local commit message.
er3ede3 (origin/master, origin/HEAD) Remote commit message.
sfe3fd3 Remote commit message.
Run Code Online (Sandbox Code Playgroud)
您现在checkout
可以在您的new_feature
分支上工作一段时间.当你完成了......
(2)git rebase master
将重播new_feature
的顶部master
.同样,您的本地提交仍然位于"本地远程HEAD指针"之上.
> git log --oneline --all -10 --decorate
fc5773d (new_feature) Local new_feature commit.
9282838 Local new_feature commit.
d34d34c (HEAD, master) Local commit.
d3434r2 Local commit.
d234d4c Local commit.
er3ede3 (origin/master, origin/HEAD) Remote commit.
sfe3fd3 Remote commit.
Run Code Online (Sandbox Code Playgroud)
该rebase
命令只是把new_feature
未来掌握,并对准他们,你需要运行...
(3)git merge new_feature
,这将进行快速合并.现在HEAD
,new_feature
并且master
都指向同一个提交.
> git log --oneline --all -10 --decorate
fc5773d (HEAD, new_feature, master) Local new_feature commit.
9282838 Local new_feature commit.
d34d34c Local commit.
d3434r2 Local commit.
d234d4c Local commit.
er3ede3 (origin/master, origin/HEAD) Remote commit.
sfe3fd3 Remote commit.
Run Code Online (Sandbox Code Playgroud)
(4)之后,您可以安全地删除new_feature
分支.推送前的最终日志将如下所示:
> git log --oneline --all -10 --decorate
fc5773d (HEAD, master) Local new_feature commit 2
9282838 Local new_feature commit.
d34d34c Local commit.
d3434r2 Local commit.
d234d4c Local commit.
er3ede3 (origin/master, origin/HEAD) Remote commit.
sfe3fd3 Remote commit.
Run Code Online (Sandbox Code Playgroud)
在new_feature分支上git rebase new_feature
运行后,无需在主分支上运行git rebase master
.在git rebase master
new_feature分支上运行之后,您可以将new_feature合并到master中 - 它将是一个快进合并,不会引入合并提交.
之所以git rebase new-feature
没有在master上播放所有新功能提交的原因是因为git识别master已经处于新功能的基础 - 我们执行了这一步git rebase master
- 而且它只是在自身上进行自我调整.因此,它只是快速转发到新功能.
此外,您不必担心推送位于远程/主提示下方的提交 - 如果您尝试,远程将拒绝您的推送(除非您提供-f选项,否则不提供).并且,如果您的本地主人正在跟踪您的远程主人,git status
将告知您的本地人是否与您的远程分支分道扬..
归档时间: |
|
查看次数: |
9489 次 |
最近记录: |