简体   繁体   English

反转git rebase工作流程

[英]reversed git rebase workflow

I have a master branch and a staging branch. 我有一个master分支和一个staging分支。

Now the usual workflow is that new changes happen in master then from staging I run a 现在通常的工作流程是在master中进行新更改,然后从暂存运行

git rebase master . git rebase master

However due to the nature of my deployment infrastructure I've had to commit a whole bunch of fixes as I was debugging directly into the staging branch. 但是,由于我的部署基础结构的性质,在直接调试到暂存分支时,我不得不提交大量修复程序。 What's the right way to bring these changes back into master so that my future git rebase will work well. 什么是将这些更改重新带回master的正确方法,以便将来的git rebase可以正常工作。

Rebase staging onto master. 将登台恢复为master。 You'll have this: 您将拥有:

         |
master - o
         |
         x
         |
         x - staging

You want this: 你要这个:

         |
         o
         |
         x
         |
master - x - staging

There's only one operation you need to do. 您只需要执行一项操作。 Set master to point to the same commit that staging points at. 将master设置为指向登台指向的同一提交。 There are umpteen ways to set master to point at the same commit as staging; 有许多种方法可以将master设置为指向与登台相同的提交; here's one: 这是一个:

git checkout master
git reset staging

A simple pull should be equivalent as well. 一个简单的拉力也应该等效。 Since master is an ancestor of staging, merging staging will be a fast-forward, unless you have configured --no-ff somewhere, which we can detect with --ff-only : 由于master是暂存的祖先,因此合并暂存将是一种快速的方法,除非您在某处配置了--no-ff ,而我们可以使用--ff-only进行检测:

git checkout master
git pull --ff-only staging

Edit: if there are commits you don't want to add back into master, make a new branch, then use rebase -i to keep just the commits that need to go back to master like this: 编辑:如果您不想将提交重新添加到master中,则创建一个新分支,然后使用rebase -i保留仅需要返回到master的提交,如下所示:

git checkout staging
git checkout  -b mypics

Yielding 屈服

         |
master - o
         |
         y
         |
mypics - x - staging

rebase mypics, dropping y, creating x': 重新整理mypics,删除y,创建x':

git rebase -i master
# Drop the lines with commits you don't want to send back to master.

         |
master - o
         | \
         y  x' - mypics
         |
         x - staging

Then set master to point to the same commit as mypics, using reset or pull as described above. 然后,使用master或如上所述,将master设置为指向与mypics相同的提交。 Then drop mypics: 然后删除近视:

git checkout master
git reset mypics
git branch -D mypics

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM