git 将更改合并到本地分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2648375/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 04:14:06  来源:igfitidea点击:

git merging changes to local branch

git

提问by ScottS

Is it possible to merge changes from a central repo to a local branch without having to commit/stash the edits on the local branch and checkout master?

是否可以将中央存储库的更改合并到本地分支,而无需在本地分支和结帐主节点上提交/存储编辑?

If I am working on local branch "work" and there are some uncommited changes, I use the following steps to get updates from the central repo into my working branch.

如果我在本地分支“工作”上工作并且有一些未提交的更改,我使用以下步骤从中央存储库获取更新到我的工作分支。

git stash
git checkout master
git pull 
git checkout work
git rebase master
git stash pop

Usually there are no uncommitted changes in "work" and then I omit the stash steps.

通常“工作”中没有未提交的更改,然后我省略了隐藏步骤。

What I would really like is something like the following:

我真正想要的是以下内容:

git pull master  (updates master while work branch is checked out and has changes)
git rebase master (rebases the updates into work branch uncommited changes are still safe)

Is there something easier than what I currently do?

有什么比我现在做的更容易的吗?

回答by P Shved

You can do (on branch work):

你可以做(​​在分支上work):

git stash
git pull --rebase origin master
git stash apply

git pull --rebaseboth pulls remote changes and rebases your local changes on top of the remote ones. I.e. essentially does what you show in your script.

git pull --rebase两者都拉取远程更改并将您的本地更改重新绑定到远程更改之上。即基本上执行您在脚本中显示的内容。

Local changes, of course, should be committed or stashed on mergeor rebase(because if merge conflict happens, conflicting changes should be uncommitted for you to resolve them--but where would your local changes go then?)

当然,本地更改应该提交或隐藏在mergerebase(因为如果发生合并冲突,冲突更改应该不提交以便您解决它们——但是您的本地更改会去哪里呢?)

When you later decide to update masterand to merge workbranch with it, it won't cause problems, since changes pulled are the same. So you don't have to update masterwhen you pull changes.

当您稍后决定更新master并与其合并work分支时,它不会引起问题,因为拉取的更改是相同的。因此,您master在拉取更改时不必更新。

回答by Pran

I don't think you can pull if you have uncommitted changes.

如果您有未提交的更改,我认为您无法拉动。

Therefore, you could do something along the lines of:

因此,您可以按照以下方式做一些事情:

git stash
git pull --rebase <remote> <branch> # Calls rebase instead of merge.
git stash pop

回答by Reversed Engineer

Maybe things have changed since 2010, but you can pull from a remote even if you have uncommited changes. Your local changes will stay uncommitted, so you can diff or merge them at your leisure.

也许自 2010 年以来情况发生了变化,但即使您有未提交的更改您也可以从远程拉取。您的本地更改将保持未提交状态,因此您可以在闲暇时区分或合并它们。

git pull origin master

Tested with git version 1.9.5.msysgit.1

使用 git 版本 1.9.5.msysgit.1 测试

From this SO answer

这个SO答案