我在我的本地分支上有 1 个提交,然后将更改从远程分支带到我的本地,我在我的本地分支上做了一个 git pull
令我惊讶的是 git
说了这个。
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
我知道我在 vi
编辑器中。
我的问题是为什么 git 要求我输入消息。我以前从未遇到过。
我的 git 版本是:version 1.9.5-preview20141217
我提到了 this问题,但我仍然觉得很难理解。 谢谢。
最佳答案
来自 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
关于您的问题:为什么
- 为什么 Git 创建 MERGE 提交:这是
git pull
的默认行为。网上有很多关于这种行为的解释,this很好地解释了它。 - 为什么 Git 现在要求提交消息:我想到了三个可能的选项:
- 你更新了你的 git 客户端
- 您以前从未有过领先于远程的本地分支机构
- 最近更改了您的 git 配置
如何避免这种情况:
由于您的本地存储库提前 1 次提交,git 会尝试将您的远程存储库 merge 到您的本地存储库。这可以通过 merge 来处理,但在你的情况下,也许你正在寻找 rebase ,即将你的提交添加到顶部。你可以用
git rebase
或 git pull --rebase
如果这确实是您正在寻找的行为,您可以设置您的 git 配置,使 rebase 成为您的 git pull
全局设置:
git config branch.autosetuprebase always # Force all new branches to automatically use rebase
或者您可以按分支设置它:
git config branch.*branch-name*.rebase true # Force existing branches to use rebase.
关于git - 为什么 git 要求输入提交信息来解释为什么这个 merge 是必要的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36418708/