为什么git要求输入提交信息来解释为什么这种合并是必要的 [英] Why git asks to enter a commit message to explain why this merge is necessary

查看:789
本文介绍了为什么git要求输入提交信息来解释为什么这种合并是必要的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地分支有1个提交,然后从远程分支到我的本地进行更改,我在本地分支上执行了 git pull ,令我吃惊 git 表示。

 #请输入提交信息以解释原因这个合并是必要的,
#特别是如果它将更新的上游合并到主题分支中。

我知道我在 vi 编辑器。



我的问题是为什么 git要求我输入消息。我从来没有面对过它。



我的git版本是: version 1.9.5-preview20141217



我提到这个问题,但我仍然觉得很难理解。
Thanks。

From Git文档


将远程存储库中的更改合并到当前分支中。在默认模式下,git pull是git fetch的缩写,然后是git merge FETCH_HEAD


至于你的问题: WHY


  1. 为什么Git创建一个MERGE commit:这是 git pull 。在互联网上有很多这种行为的解释,
  2. 为什么Git现在要求提交提交消息:我想到了三种可能的选项:


    • 您更新了您的git客户端

    • 您之前从未拥有位于远程的本地分支

    • 您的git配置最近已更改


如何避免这种情况:

因为您的本地存储库提前1次提交,所以git会尝试将您的远程合并到本地仓库。这可以通过合并来处理,但就你而言,也许你正在寻找rebase,即将你的提交添加到顶端。您可以使用

git rebase git pull --rebase $ b如果这确实是你正在寻找的行为,你可以设置你的git配置来使rebase成为你的的默认选项, git pull



全局设置:

  git config branch.autosetuprebase always#强制所有新分支自动使用rebase 

或者您可以为每个分支设置它:

  git config分支。* branch-name * .rebase true#强制现有分支机构使用rebase。 


I had 1 commit on my local branch, then to take the changes from remote branch into my local, I did a git pull on my local branch and to my surprise git said this.

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

I understand that I'm in vi editor.

My question is why git asked me to enter the message. I never faced it before.

My git version is: version 1.9.5-preview20141217

I referred this question but I'm still finding it hard to understand. Thanks.

解决方案

From Git Documentation:

Incorporates changes from a remote repository into the current branch. In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD

As to your question about: WHY

  1. Why is Git creating a MERGE commit: That is the default behavior of git pull. There are lots of explanation of this behavior on the internet, this does a good job of explaining it.
  2. Why is Git asking for a commit message now: Three possible options come to my mind:
    • You updated your git client
    • You never had a local branch which was ahead of the remote before
    • Your git config was changed recently

How to avoid this:

Since your local repository is 1 commit ahead, git tries to merge your remote to your local repo. This can be handled via merge, but in your case, perhaps you are looking for rebase, i.e. add your commit to the top. You can do this with

git rebase or git pull --rebase

If this is indeed the behavior you are looking for, you can setup your git config to make rebase a default option for your git pull

Set it up globally with:

git config branch.autosetuprebase always # Force all new branches to automatically use rebase

Or you can set it up per branch:

git config branch.*branch-name*.rebase true # Force existing branches to use rebase.

这篇关于为什么git要求输入提交信息来解释为什么这种合并是必要的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆