如何解释git日志中的括号? [英] How to interpret the brackets in the git log?
问题描述
运行 git log
给我这样的输出:
commit 69b6309f09365c09a2fe10f09aee801d1fae29ee(HEAD-> master,edeviserBranch)作者:eDeviser< eDeviser@xyz.com>日期:2019年9月2日星期一09:53:07 +0200添加了foo提交59a08270fb730db259a8d5819bb585a613024d97(来源/主文件,来源/HEAD)作者:eDeviser< eDeviser@xyz.com>日期:2019年9月2日星期一09:49:50 +0200更多文字
我不明白方括号内内容的含义.方括号内的文字是什么意思?这是提交所基于的分支吗?如果是, HEAD->之间有什么区别?master
, origin/master
和 origin/HEAD
?
如何解释git日志中的括号?
简短答案
这是指向相应提交的指针的列表.我建议您阅读有关 HEAD
和 origin
的信息.
提交和指针
在 git
中,您具有提交和在这些提交之间移动的指针.分支只是指向提交的指针.假设您有一个分支 mybranch
,那么 mybranch
只是一个指针.如果您在该分支上提交,则指针 mybranch
会继续移至该提交.
HEAD指针
HEAD
: HEAD
指针指向您的存储库所在的当前提交.在您的情况下,它指向的是提交 69b6309f09365c09a2fe10f09aee801d1fae29ee
,即:您的仓库现在处于提交 69b6309f09365c09a2fe10f09aee801d1fae29ee
上.括号中的内容是其他指针的列表,这些指针指向与 HEAD
相同的提交,在您的情况下为 master
和 edeviserBranch
.从这些信息中,您可以看到 master
和 edeviserBranch
尚未分开.您可能将带有文本加了foo
的最后一次提交推送到 master
上,然后从 master
创建了一个新的分支 edeviserBranch
.
工作区
来源
: git
给远程仓库的默认名称.使用 origin/< pointer>
,您可以访问工作区中的分支.工作区是本地存储库和远程存储库之间的空间. git fetch origin
将数据从远程存储库下载到本地存储库的工作区.它不会合并任何数据,只会下载它.阐明工作区概念的示例:
git获取原点#从远程原点更新数据.#例如,您的远程分支edeviserBranch将被下载到您的工作区#,可以从origin/edeviserBranch访问.git checkout master#转到您的本地master分支git merge origin/edeviserBranch#从您的工作区域合并分支edeviserBranch#到您当地的master分支
原点/HEAD指针
origin/HEAD
:工作区中的一个指针,它指向默认提交,该副本将由克隆您的存储库的人签出.
根据 git log
的输出,指针 origin/master
和 origin/HEAD
都指向提交 59a08270fb730db259a8d5819bb585a613024d97 代码>.
如果您的工作区未与远程仓库同步,并且您执行了 git fetch origin
(这样做,您将使用远程仓库更新工作区),则这些指针将改变./p>
Running git log
gives me an output like this:
commit 69b6309f09365c09a2fe10f09aee801d1fae29ee (HEAD -> master, edeviserBranch)
Author: eDeviser <eDeviser@xyz.com>
Date: Mon Sep 2 09:53:07 2019 +0200
added foo
commit 59a08270fb730db259a8d5819bb585a613024d97 (origin/master, origin/HEAD)
Author: eDeviser <eDeviser@xyz.com>
Date: Mon Sep 2 09:49:50 2019 +0200
More Text
I don't understand the meaning of the content inside the brackets. What is the meaning of the text inside the brackets? Is this the branch which is the commit based on? If yes, what is the difference between HEAD -> master
, origin/master
and origin/HEAD
?
How to interpret the brackets in the git log?
Short answer
It is a list of pointers which are pointing to the corresponding commit. I recommend you read about HEAD
and origin
.
Commits and pointers
In git
, you have commits and pointers moving in between those commits. A branch is just a pointer which points to a commit. Say you have a branch mybranch
, then mybranch
is just a pointer. If you commit on that branch, the pointer mybranch
just moves on to that commit.
The HEAD pointer
HEAD
: the HEAD
pointer points to the current commit your repo is on. In your case, it is pointing to commit 69b6309f09365c09a2fe10f09aee801d1fae29ee
, that is: your repo is now on commit 69b6309f09365c09a2fe10f09aee801d1fae29ee
. The content in parenthesis is a list of other pointers which point to the same commit as HEAD
, which, in your case are master
and edeviserBranch
. From that information, you can see that master
and edeviserBranch
have not diverged yet. You probably pushed the last commit with text added foo
onto master
and then created a new branch edeviserBranch
from master
.
The working area
origin
: the default name that git
gives to your remote repo. With origin/<pointer>
, you can access branches in your working area. The working area is a space between your local and remote repositories. git fetch origin
downloads the data from your remote repo to the working area of your local repo. It doesn't merge any data, it just downloads it. An example to make the concept of working area clear:
git fetch origin # update data from remote origin.
# For example, your remote branch edeviserBranch will be downloaded to your working area
# and can be accessed from origin/edeviserBranch.
git checkout master # go to your local master branch
git merge origin/edeviserBranch # merge branch edeviserBranch from your working area
# to your local master branch
The origin/HEAD pointer
origin/HEAD
: a pointer in your working area which points to the default commit that will be checked out by someone cloning your repository.
According to the output of git log
, pointer origin/master
and origin/HEAD
both point to commit 59a08270fb730db259a8d5819bb585a613024d97
.
If your working area is not synchronized with your remote repo, and you execute git fetch origin
(and doing so, you update your working area with your remote repo), those pointers will change.
这篇关于如何解释git日志中的括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!