简体   繁体   English

如何将更改从 git 远程分支移动到新分支

[英]How to move changes from a git remote branch to a new branch

I created my-feature-branch branch from our develop branch, committed my changes to it and raised a PR to merge it back to develop .我从我们的develop分支创建了my-feature-branch分支,提交了我的更改并提出了一个 PR 将其合并回develop

However, boss said, what I should have done is, created a my-feature-branch from develop , then created a my-story-branch off my-feature-branch , committed my changes to my-story-branch and raised a PR to merge my-story-branch back to my-feature-branch .但是,老板说,我应该做的是,从develop创建一个my-feature-branch ,然后从 my-feature-branch 创建一个my-story-branch my-feature-branch ,将我的更改提交给my-story-branch并提出 PR将my-story-branch合并回my-feature-branch

When all the stories of my-feature-branch have been completed, then it will be merged back to develop .my-feature-branch的所有故事都完成后,它将被合并回develop

So, to fix this, I thought of doing like this:所以,为了解决这个问题,我想这样做:

  1. manually copy my changes (12 files in total) to someplace else in my computer手动将我的更改(总共 12 个文件)复制到计算机中的其他位置
  2. delete all branches I created删除我创建的所有分支
  3. Create my-feature-branch again, and then create my-story-branch off it再次创建my-feature-branch ,然后创建my-story-branch关闭它
  4. manually paste my changes手动粘贴我的更改
  5. commit and raise PR提交并提高 PR

Is there a shorter way to accomplish this without deleting branches and manually copy pasting my changes?有没有更短的方法可以在不删除分支并手动复制粘贴我的更改的情况下完成此操作?

EDIT :编辑

what I did (current state of my git - changes have been pushed to remote)
------------------------------------
    x-x-x (develop)
         \
          x-x' (my-feature-branch)

The above should now be changed to:
----------------------------------
x-x-x (develop)
         \
          x (my-feature-branch)
           \
            x-x' (my-story-branch)

And then raise a PR to merge my-story-branch to my-feature-branch

Since you have already pushed my-feature-branch to the remote (assuming origin ) we should probably remove that.由于您已经将my-feature-branch推送到远程(假设origin ),我们可能应该删除它。 Make sure that no-one else is using that branch.确保没有其他人在使用该分支。

git push -d origin/my-feature-branch
# (if force has to be used)
# git push -f -d origin/my-feature-branch

We can rename the local my-feature-branch to be my-story-branch and push that.我们可以将本地my-feature-branch重命名为my-story-branch并推送它。

git checkout my-feature-branch
git branch -m my-story-branch
git push origin my-story-branch

And because we still need my-feature-branch to merge into, we can create that and push it too.因为我们仍然需要my-feature-branch来合并,所以我们可以创建它并推送它。

git checkout develop
git checkout -b my-feature-branch
git push origin my-feature-branch

A simplified git tree should look like this:简化的 git 树应如下所示:

x-x-x (develop)(my-feature-branch)
         \
          x-x-x' (my-story-branch)

Once my-story-branch has been merged with my-feature-branch it should look like this:一旦my-story-branchmy-feature-branch合并,它应该如下所示:

x-x-x (develop)-x (my-feature-branch)(my-story-branch)
         \     /
          x-x-x'

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

相关问题 如何将更改从一个分支移动到另一个分支 git? - How to move the changes from one branch to another branch git? 如何在GIT上将更改从开发分支上传到远程分支? - How to upload changes from development branch to remote branch on GIT? Git:如何从“无分支”推送到新的远程分支? - Git: How to push from “no branch” to a new remote branch? git将未经更改的更改从主分支移动到新分支 - git move uncommited changes from master to new branch Git:将分段的更改移到其他分支或新分支 - Git : Move staged changes to different or new branch 如何将更改从分支A推送到分支B而不从B分支git删除新更改(不合并) - How to push changes from branch A to branch B without removing new changes from B branch git (no merge) git:在合并分支之前如何将更改移动到新文件? - git: How to move changes to a new file before merging the branch? 如何从远程仓库中的 master 删除 GIT 分支并从另一个分支启动新分支? - How to delete GIT branch from master in remote repo and start a new branch from another branch? GIT:将更改从一个分支移动到另一个分支 - GIT: Move changes from one branch to other git:如何将提交的更改从master移动到branch? - git: how to move committed changes from master to branch?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM