如何知道哪个提交属于哪个分支 [英] How to know which commit belongs to which branch

查看:78
本文介绍了如何知道哪个提交属于哪个分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用git log --graph(或它的别名)时,如何确定哪个提交(*)属于哪个分支?

When I use git log --graph (or my alias for it) how can I tell which commit (*) belongs to which branch?

这是我的gitconfig

Here's my gitconfig

tree = log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(boldblue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(black)%s%C(reset)%C(dim black)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all

任何帮助都会动摇!

更新 我最终使用: git log --all --graph --format = format:'%C(蓝色)%h%C(重置)%C(黑色)%s%s%C(重置)%C(红色)%d% C(重置)%C(绿色),%an,%ar%C(重置)'

Update I ended up using: git log --all --graph --format=format:'%C(bold blue)%h%C(reset) %C(dim black)%s%C(reset)%C(bold red)%d%C(reset) %C(green)by %an, %ar%C(reset)'

推荐答案

我只使用git log --all --graph --oneline --decorate.

当您进行提交时,Git会重新排列该图,以始终显示从右向左进入的合并.因此,即使它开始变得一团糟,您也总是可以知道什么是分支,以及分支的合并位置.这是我的一个仓库中的一个示例片段,由上述log命令输出:

Git rearranges this graph as you make commits to always show merges coming in from the right toward the left. You can always tell what's a branch, and where it's merging because of this, even when it starts to get all twisty. Here's an example snippet from one of my repos, as output by the above log command:

| * af8bb24 Remove mayaaxis.py
| * 39b27d7 Remove axis.py
|/  
*   a12c712 Merge branch 'MayaObject'
|\  
| * 755c024 Elide pymel.core.animation import in core.py
| * 6de87c2 Clean up imports in core.py
| * 4b70adf Move core.RefGrid to new grid.py
| *   40d3c7d Merge branch 'absorbMayaRef' into MayaObject
| |\  
| | * 58305e5 Add core.MayaObject test for refFile property
| | * 154af30 Refactor core.MayaObject refPath to refFile
| | * d23fe77 Condense namespace work in core.MayaRef.loadRef
| | * 22c780b Add missing test for core.MayaRef namespace arg
| |/  
| * 6843970 Remove projPath arg from core.MayaRef constructor
| * 692578a Add docstrings to core.MayaObject test classes
| * acb4d75 Add core.MayaObject init defaults test
| * b8f1ae6 Stub in core.MayaObject
|/  
* 4dc6112 Make __init__.py imports relative
* abde256 Add *.swp, and *.swo to .gitignore

请注意在顶部附近的a12c712提交-这是以前的'MayaObject'分支的合并,该分支在4dc6112提交处从底部开始.您可以看到它在底部向右分支,并在顶部附近向左合并.在'MayaObject'分支上的第一个提交是b8f1ae6,它在右边分支,分支总是在右边分支,合并总是在左边.

Note the a12c712 commit near the top - that's a merge of the former 'MayaObject' branch, which started near bottom at the 4dc6112 commit. You can see it branch off to the right at the bottom, and merge back in to the left near the top. The first commit on the 'MayaObject' branch was b8f1ae6, which forks off to the right - branching always goes off to the right, merging always comes in toward the left.

您还可以看到,当我在'MayaObject'分支上时,我决定再次跳楼并在'absorbMayaRef'分支上工作,该分支是6843970的分支,它的第一个提交是22c780b.它在40d3c7d处合并回'MayaObject',然后如开头所述,'MayaObject'在a12c712处合并回master分支.

You can also see that while I was on the 'MayaObject' branch, I decided to jump off again and work on the 'absorbMayaRef' branch, which forked off of 6843970, and it's first commit was 22c780b. It merged back into 'MayaObject' at 40d3c7d, and then 'MayaObject' - as stated at the beginning - merged back into the master branch at a12c712.

保留自动生成的合并提交消息(例如,将将分支'absorbMayaRef'合并到MayaObject中"),您将始终能够知道哪个属于哪个分支.如果您在进行合并提交时删除或覆盖这些消息,那么您将无法确定哪个分支位于哪个分支上.

Leave the auto-generated merge commit messages (e.g. "Merge branch 'absorbMayaRef' into MayaObject") intact, and you'll always be able to tell what belonged to which branch. If you delete or overwrite those messages when making merge commits, then you will not be able to tell what was on which branch.

我总是在提交内容中明确指出我所触摸的内容,因为通常这只是一个文件中的一些小更改.请注意,这四个提交是如何从22c780b58305e5的,包括端值,都提到'core.MayaRef'或'core.MayaObject'.即使我没有40d3c7d合并告诉我这是'absorbMayaRef'分支,我仍然可以很快看到该功能分支与核心模块中的某些内容有关,并且与那些2类特别.当我的更改涉及到一堆文件时,我会尝试弄清楚这一点,并大体记下更改中发生的情况,例如在整个库中重构路径名",或在多个测试文件中重组测试".

I always make it clear in my commits what I touched, because it's usually some small change in one file. Note how the 4 commits from 22c780b to 58305e5, inclusive, all mention 'core.MayaRef' or 'core.MayaObject'. Even if I didn't have the 40d3c7d merge telling me that was the 'absorbMayaRef' branch, I'd still be able to see pretty quickly that that feature branch had to do with something in the core module, and with those 2 classes in particular. When my changes touch a bunch of files, I try to make that clear, and note in general what happened in the change, e.g. "Refactor path names across library", or "Reorganize tests in several test files".

这篇关于如何知道哪个提交属于哪个分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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