如何检查git日志以查找“快进”合并? [英] How do I check git log for a "fast-forward" merge?

查看:156
本文介绍了如何检查git日志以查找“快进”合并?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的例子中,有没有办法知道发生了合并?

 #setup示例目录
$ mkdir test $ b查看git log,我无法判断是否合并了。 $ b $ cd test
$ git init
$ touch a
$ git add a
$ git commit -m1

#switch to不同的分支
$ git checkout -b主题
$触摸b
$ git add b
$ git commit -m2

#返回要掌握和合并
$ git checkout master
$ git合并主题

#git log

commit cccc64de3947828f487a8ce3c3e72b0f68dc88c3
作者:none
日期:五月20 05:54:45 2011 -0700

2

提交a5d57454295759609d91a60219002e74016eed2b
作者:none
日期:5月20日星期五05:54:29 2011 -0700

1


解决方案

在这个例子中,git发现可以做一个所谓的快进合并,因为你合并的分支已经包含了当前分支中的所有内容 - 它不需要创造一个如果您不喜欢该行为,并且希望即使在可以进行快速转发的情况下创建合并提交,也可以在提交图中提交新的提交以加入两个分支。

你应该在另一个分支中合并:

  git merge --no-ff topic 
git reflog
会产生以下输出:

  1eecbcb HEAD @ {0}:合并主题:快进
193ae5e HEAD @ {1}:结帐:从主题移动到主
1eecbcb HEAD @ {2}:commit:2
193ae5e HEAD @ {3}:结帐:从主人移动到主题
193ae5e HEAD @ {4}:提交(初始):1

...它向您展示了最近如何改变 HEAD ,以及导致这种情况发生的原因。然而,依赖于reflog通常是一个糟糕的主意,除非在特定的情况下,比如从错误中恢复 - 最好是从提交图的角度思考,并且让它代表你所做的。 git merge --no-ff 就是很多人喜欢的一种方法。


In the following example, is there a way to know a merge happened? Looking at git log, I can't tell I merged.

# setup example directory
$ mkdir test
$ cd test
$ git init
$ touch a
$ git add a
$ git commit -m "1"

# switch to different branch
$ git checkout -b topic
$ touch b
$ git add b
$ git commit -m "2"

# go back to master and merge
$ git checkout master
$ git merge topic

# git log

commit cccc64de3947828f487a8ce3c3e72b0f68dc88c3
Author: none
Date:   Fri May 20 05:54:45 2011 -0700

    2

commit a5d57454295759609d91a60219002e74016eed2b
Author: none
Date:   Fri May 20 05:54:29 2011 -0700

    1

解决方案

In that instance, git has spotted that it's possible to do a so-called "fast-forward" merge, since the branch you're merging in already contains everything in the current branch - it doesn't need to create a new commit in the commit graph to join the two branches.

If you don't like that behaviour, and want create a merge commit even when fast-forwarding is possible, you should merge in the other branch with:

git merge --no-ff topic

However, if you really need to know whether a merge happened or not, you can find that information in the "reflog". For example, in your situation, git reflog would produce the following output:

1eecbcb HEAD@{0}: merge topic: Fast-forward
193ae5e HEAD@{1}: checkout: moving from topic to master
1eecbcb HEAD@{2}: commit: 2
193ae5e HEAD@{3}: checkout: moving from master to topic
193ae5e HEAD@{4}: commit (initial): 1

... which shows you how HEAD was changed recently, and what action caused that to happen. However, relying on the reflog is generally a bad idea except in particular situations, such as recovering from errors - it's better to just think in terms of the commit graph, and make that represent what you've done. git merge --no-ff is one such method that lots of people like.

这篇关于如何检查git日志以查找“快进”合并?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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