英文:
How to update local master and merge a feature branch in a shorter way
问题
以下是翻译好的部分:
我的合并特性分支与上游远程的工作流程是:
git stash / commit # 保存当前特性分支上的工作
git checkout master
git pull
git checkout feature
git merge master
对我来说,似乎多了一步。是否有更简洁的工作流程来实现这一点?也许我可以运行 git fetch
并与 origin/master
合并,但这样我的本地 master 分支会过时?
英文:
My workflow to merge my feature branch with upstream remote is:
git stash / commit # save current work on feature branch
git checkout master
git pull
git checkout feature
git merge master
It seems to me I'm doing one too many steps. Is there a shorter workflow to achieve this? I could perhaps run git fetch
and merge with origin/master
but then my local master would go out of date?
答案1
得分: 2
你是正确的。
你可以执行
git commit
git fetch
git merge origin/master
git fetch会获取来自origin的最新更改,将其合并到origin/master分支,然后你可以将其合并到你的特性分支中。
英文:
You're correct.
You can do
git commit
git fetch
git merge origin/master
git fetch will get the latest changes from origin onto the origin/master branch allowing you to merge it into your feature branch.
答案2
得分: 2
你不需要更新你的"local master",或者切换到master
分支来更新origin/master
,因为你实际上想要与之保持同步的是origin/master
。你只需要运行git fetch
,它会从远程拉取变更。
一旦你拉取了变更,你可以使用rebase
命令将你的分支上的提交移到从远程拉取的内容之上,通常我会使用rebase -i
来执行这个操作,这样我可以查看我正在移动的提交。
完整的步骤是:
git fetch
git stash
git rebase -i origin/master
git stash pop
请注意,就像每次执行rebase操作时一样,你应该确保你是唯一在这个分支上工作的人。否则,你会创建不同的分支,当其他人尝试合并你的变更时可能会出现问题。
英文:
You don't need to update your "local master", or change to the master
branch in order to update origin/master
, which is the thing you actually want to keep up-to-date with. All you need is git fetch
which pulls in changes from the remote.
Once you've pulled in changes, you can rebase
onto origin/master
to move the commits from your branch on top of whatever has come in from the remote. I typically use rebase -i
for this, so I can review the commits I'm moving.
The full set of steps is:
git fetch
git stash
git rebase -i origin/master
git stash pop
Note that, as is always the case when rebasing, you should make sure you are the only person working on the branch. Otherwise you will create divergent branches and there will be problems when other people try to incorporate your changes.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论