Git pull 要求我写合并消息

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

Git pull asks me to write merge message

gitgit-mergegit-pull

提问by Pratik

I pull from my branch:

我从我的分支拉:

git checkout mybranchSample
git fetch
git pull origin master

Then, Git gives me the following message:

然后,Git 给了我以下消息:

Please enter a commit message to explain why this merge is necessary,
especially if it merges an updated upstream into a topic branch

请输入提交消息以解释为什么需要进行此合并,
尤其是将更新的上游合并到主题分支时

enter image description here

在此处输入图片说明

And after entering a commit message, it merges masterinto my files. And even though I haven't worked on some files from master, it shows the files list in green when I type git status.

输入提交消息后,它会合并master到我的文件中。即使我没有处理过来自 的某些文件master,当我输入git status.

This issue is nothappening with my colleagues, but me only. What can be the reason behind this?

这个问题不是发生在我的同事身上,而是发生在我身上。这背后的原因是什么?

回答by Madara's Ghost

git pullis basically two actions at once: git fetchfollowed by a git merge(unless you use git pull --rebase, in which case you can guess what happens).

git pull基本上是同时执行两个操作:git fetch后跟 a git merge(除非您使用git pull --rebase,在这种情况下您可以猜到会发生什么)。

The reason you're seeing this is because Git can't do a fast-forwardmerge, like it can most of the time. The reason for that is usually because you've git committed locally to the branch you're trying to pull, and now you need to merge the remote changes with your local ones.

你看到这个的原因是因为 Git 不能像大多数时候那样进行快进合并。这样做的原因通常是因为您已经git commit在本地尝试拉取分支,现在您需要将远程更改与本地更改合并。

It's also worth noting that Git pre-populated the merge message for you, so you don't really need to type anything. Just save and exit, and the merge should be complete. (Unless, of course, there are merge conflicts).

还值得注意的是,Git 为您预先填充了合并消息,因此您实际上不需要输入任何内容。只需保存并退出,合并就完成了。(当然,除非有合并冲突)。

回答by tne

Linus Torvalds explains it best:

Linus Torvalds 解释得最好:

Spreading the word about an upcoming 'git' UI change, since I'm largely to blame.

This change hopefully makes people write merge messages to explain their merges, and maybe even decide not to merge at all when it's not necessary.

I've been using that git feature for the last few weeks now, and it has resulted in my merges from submaintainers having various notes in them (well, at least if the submainter gave me any). So I'm trying to lead by example.

But if you don't like explaining your merges, this might be annoying. Of course, if you don't explain your merges, you are annoying, so it all evens out in the end. "Karmic balance", so to say.

传播有关即将到来的“git”UI 更改的消息,因为这主要归咎于我。

这一变化有望让人们编写合并消息来解释他们的合并,甚至可能决定在没有必要时根本不合并。

过去几周我一直在使用该 git 功能,这导致我从子维护者那里合并了各种注释(好吧,至少如果子维护者给了我的话)。所以我试图以身作则。

但是如果你不喜欢解释你的合并,这可能会很烦人。当然,如果你不解释你的合并,你会很烦人,所以最后一切都会平衡。“业力平衡”,可以这么说。

Source: https://plus.google.com/+LinusTorvalds/posts/SrePhcj6XJe

来源:https: //plus.google.com/+LinusTorvalds/posts/SrePhcj6XJe

回答by Martin Rauscher

The reason this is only happening to you is not that your config is different, but that the branch you're merging in is different.

这只是发生在你身上的原因不是你的配置不同,而是你合并的分支不同。

The reason for the files in the diff that you did not change is that after a merge, the new commit has to parent commits: The commit you did last and the newest commit on master. The new commit contains all changes/files. So if you diff from newto your last commityou will see all the files as changed/added that were changed/added on master while your branch was out of sync with the master branch.

您没有更改差异中的文件的原因是合并后,新提交必须是父提交:您上次提交的提交和最新提交的主提交。新提交包含所有更改/文件。因此,如果您将提交上次提交不同,您将看到在您的分支与主分支不同步时在主分支上更改/添加的所有文件都已更改/添加。

回答by misch

I think you have an issue with the branches... The 2 possible scenarios I could imagine you're facing:

我认为你的分支有问题......我可以想象你面临的两种可能的情况:

1) You have a remote branch, mybranchSample, and you wanna work on it - you have nothing to do at the moment with the master branch (that is, you don't wanna merge your branch into master or vice versa). You say in your question

1) 你有一个远程分支,mybranchSample并且你想在它上面工作——你现在与 master 分支没有任何关系(也就是说,你不想将你的分支合并到 master 中,反之亦然)。你在你的问题中说

When I take pull from my branchafter fetch like ...

当我在获取后从我的分支中拉出时......

But what you do is git pull origin master, which pulls from master. Instead, you should be able, with git version >= 1.6.6, to checkout your remote branch using

但是你所做的是git pull origin master,从master那里拉。相反,您应该能够使用 git version >= 1.6.6,使用

git fetch
git checkout mybranchSample


2) You try to work on mybranchSamplebut wanna have the latest code from the master branch there. Then it makes sense that a merge might be necessary, as Anand S said.

2)您尝试继续工作,mybranchSample但想要从那里的 master 分支获得最新代码。那么正如 Anand S 所说,合并可能是有必要的。

回答by Anand S

If you were trying to merge masterto mybranchSamplebranch, then this is perfectly normal.

如果您试图合并mastermybranchSample分支,那么这是完全正常的。

Git merges masterto mybranchSample(when you did git pull origin masterfrom mybranchSamplebranch) and commitsthe merge changes for you (unless there is any conflict) and gives you the pre-populated message. You can just save and exit.

Git 合并mastermybranchSample(当您git pull origin mastermybranchSample分支执行时)并且commits合并为您更改(除非有任何冲突)并为您提供预先填充的消息。您只需保存并退出即可。

BUTIf you were just trying to get the latest code from the remote masterbranch to merge with local masterbranch, then you should checkout out to masterand then pull from master.

如果你只是试图从远程最新的代码master分支与合并本地master分支,那么你应该结帐出来master,然后从拉master

from you statement

从你的声明

it merges master files into my files. And even though I havent worked on some files from master, it shows the files list in Green when I type git status.

它将主文件合并到我的文件中。即使我没有处理过 master 的一些文件,当我输入 git status 时,它会以绿色显示文件列表。

I think you are trying to do the second one.

我认为你正在尝试做第二个。

so, try:

所以,尝试:

git checkout master
git pull origin master

回答by plushyObject

Just to try to give everyone a simple answer, and please correct me if I am not correct:

只是试图给大家一个简单的答案,如果我不正确,请纠正我:

This seems to happen when you git pullafter committing on the branch. Your local changes don't exist on the remote so it makes a commit to get everything synced.

当您git pull在分支上提交后似乎会发生这种情况。远程上不存在您的本地更改,因此它会提交以同步所有内容。