为什么Git创建没有文件更改的合并提交? [英] Why did Git create a merge commit with no file changes?

查看:118
本文介绍了为什么Git创建没有文件更改的合并提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与某人合作开展一个项目,所以我们决定使用git。不幸的是,我们经常在没有互联网的地方编码,所以我们最终得到了这样的结果:

  origin / master:A- --B --- C 
\
mylocalmaster:D --- E --- F
\
hismaster:G --- H --- I

现在,假设他推他的提交并得到这个:

  origin / master:A --- B --- C --- G --- H --- I 
\
master本地):D --- E --- F

我想要做的就是推我的提交在本地回购和在线回购中获得这个:

  A --- B --- C --- D --- E --- F --- G --- H --- I 

它当我做 git push 时似乎工作,但当我做 git fetch ,然后 git merge 。我试图做的是让他的提交到我的本地仓库中,但最终我得到了一个合并提交,其内容如合并远程跟踪分支'origin / master' 作为它的消息。



我不想做这个毫无意义的提交,因为在我们的提交中没有冲突的代码的。我们正在研究完全不同的文件,因此没有理由进行此提交。如何防止git创建此合并提交?

解决方案

您可以省略创建合并提交,通过使用 rebase 而不是 merge

正如@Dougal所说,如果您执行 git fetch ,你可以执行 git rebase 来改变你获取的 HEAD

通常情况下,您通过从远程存储库中提取来创建那些不需要的合并提交
在这种情况下,您可以添加 - rebase 选项:

  git pull --rebase 

或者将适当的选项添加到Git配置文件(本地):

  git config分支。<分支名称 - 此处> .rebase true 

或所有新的存储库和分支:

  git config branch.autosetuprebase总是 - 全局

然而,rebasing会创建更清晰,更线性的历史记录创建合并提交是很好的,两个分支都发生了巨大的变化(使用 git merge 来实现)。


I am collaboratively working on a project with someone, so we decided to use git. Unfortunately, we frequently code in locations with no internet, so we end up with something like this:

origin/master: A---B---C
                        \
mylocalmaster:           D---E---F
                        \
hismaster:               G---H---I

Now, say he pushes his commits and gets this:

origin/master: A---B---C---G---H---I
                        \
master (local):          D---E---F

All I want to do is push my commits to get this in both my local repo and the online one:

A---B---C---D---E---F---G---H---I

It seems to work when I do git push, but the trouble arises when I do git fetch and then git merge. All I'm trying to do is get his commits into my local repo, but I end up with a merge commit saying something like Merge remote-tracking branch 'origin/master' as its message.

I don't want to have this pointless commit, since there is no conflicting code in our commits. We are working on completely different files, so there's no reason to have this commit. How can I prevent git from creating this merge commit?

解决方案

You can omit creating merge commits, by using rebase instead of merge.

As @Dougal said, if you do git fetch, you can execute git rebase afterwards to change the base of your changes to the fetched HEAD.

Usually you create those unwanted merge commits, by pulling from remote repository. In that case you can add --rebase option:

git pull --rebase

or add the proper option to Git config file (locally):

git config branch.<branch-name-here>.rebase true

or for all the new repositories and branches:

git config branch.autosetuprebase always --global

However, rebasing creates cleaner, more linear history it is good to create merge commits, where there are massive changes in both branches (use git merge to do so).

这篇关于为什么Git创建没有文件更改的合并提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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