强制 GIT 拉取而不提交

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8317857/
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 06:12:27  来源:igfitidea点击:

Force GIT Pull without commiting

gitversion-controlmergepull

提问by Jean

I do a

我做一个

git pull

and I get merge conflicts. I resolve the merge conflicts manually and issues a pull again but Git refuses to do it as Git is still thinking that there are merge conflicts.

我遇到合并冲突。我手动解决了合并冲突并再次发出 pull 但 Git 拒绝这样做,因为 Git 仍然认为存在合并冲突。

Is there any way to force Git to perform a pull again and make it look for “diffs” (if any ) from the head(without committing the changes I made) ?

有什么方法可以强制 Git 再次执行 pull 并让它从头部寻找“差异”(如果有的话)(不提交我所做的更改)?

回答by Lily Ballard

Why are you issuing a second git pullafter fixing the merge conflicts from the first? That makes no sense. Once you fix the merge conflicts, you want to git commitinstead, which will create the merge commit that merges the remote branch with your local one (and includes your conflict resolutions).

为什么git pull在修复第一个合并冲突后发出第二个?这是没有意义的。一旦您修复了合并冲突,您希望git commit改为创建合并提交,将远程分支与您的本地分支合并(并包括您的冲突解决方案)。

回答by Joel

You have to commit your changes after you resolve the conflicts and push them back. Usually instead of using git pull I do a git fetchfollowed by a git mergeand then git commit. This will only fetch the upstream changes, allow you manually merge and resolve conflicts, then commit them locally. When you're ready push the changes back to upstream.

您必须在解决冲突后提交更改并将其推回。通常我不使用 git pull 而是执行git fetcha git merge,然后是git commit。这只会获取上游更改,允许您手动合并和解决冲突,然后在本地提交它们。当您准备好将更改推送回上游。

If you use this workflow you could:

如果您使用此工作流程,您可以:

git fetch
git merge 
#resolve conflicts
git commit
git fetch #check for new changes
#eventually
git push

回答by Giorgio Previtera

In addiction, after pulled, merged and committed, you can also try (assuming your remote is 'origin', of course)

上瘾后,在 pull、merge 和 commit 之后,您也可以尝试(当然,假设您的遥控器是 'origin')

git remote show origin

It's very reassuring for me!

这让我很放心!

回答by Dan Ray

The process here is:

这里的过程是:

git pull

You get a notice of conflicts. You use whatever you use (though hopefully you've hooked up everything you need to use git difftoollocally...

您会收到冲突通知。你使用任何你使用的东西(尽管希望你已经连接了你需要在git difftool本地使用的所有东西......

Once the conflicts are resolved, you now have a working directory that contains the merged of the remote changes and your local changes. The ONLY thing that's different is, git couldn't do the merge on its own and needed your help.

冲突解决后,您现在拥有一个工作目录,其中包含远程更改和本地更改的合并。唯一不同的是,git 无法自行进行合并,需要您的帮助。

You now

你现在

git commit

to create a new commit in your local repo that is the sum of the pulled-in remote changes and your local changes. Then you

在您的本地存储库中创建一个新提交,该提交是拉入的远程更改和您的本地更改的总和。那么你

git push

to publish your changes, nicely merged up, with the remote head.

发布您的更改,很好地合并,与远程头。