git 如何打印当前分支以外的分支的日志?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31368434/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:23:15  来源:igfitidea点击:

How can I print the log for a branch other than the current one?

gitbranchgit-checkoutgit-loggit-stash

提问by BanksySan

I'm on a branch with some changes. Changing branch is a pain as some files are locked by processes, so to change branch I'd have to stop all the processes which have locks, then stashthe changes before checking out the other branch to see its log.

我在一个有一些变化的分支上。更改分支很痛苦,因为某些文件被进程锁定,因此要更改分支,我必须停止所有具有锁定的进程,然后stash在检查另一个分支以查看其日志之前进行更改。

Is it possible to view the log for a different branch, without having to check it out?

是否可以查看不同分支的日志而无需检查?

回答by jub0bs

TL; DR

TL; DR

Use

git log <branch>

where <branch>is the name of the branch of interest.

<branch>感兴趣的分支的名称在哪里。

From the git-logman-page...

git-log手册页...

A simplified version of the git-logsynopsis given in that command's man pageis

该命令手册页中git-log给出的概要的简化版本是

git log [<revision range>]

Further down, you can find the following passage:

再往下,你可以找到以下段落:

When no <revision range>is specified, it defaults to HEAD(i.e. the whole history leading to the current commit)

当没有<revision range>指定时,它默认为HEAD(即导致当前提交的整个历史记录)

In others words, git logis equivalent to git log HEAD. If you're on a branch, called mybranch, say, this command is also equivalent to git log mybranch.

换句话说,git log相当于git log HEAD。如果您在一个名为 的分支上,mybranch例如,此命令也等效于git log mybranch.

You want to limit the log to commits reachable from another branch, i.e. a branch you're not currently on. The easiest way to do that is to explicitly pass the name of the branch of interest to git log:

您想将日志限制为可从另一个分支访问的提交,即您当前不在的分支。最简单的方法是将感兴趣的分支的名称显式传递给git log

git log <branchname>

See the gitrevisions manpagefor more details about the many forms that the <revision-range>argument can take.

有关参数可以采用的多种形式的更多详细信息,请参阅gitrevisions 联机帮助页<revision-range>