Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to interpret the brackets in the git log?

Running git log gives me an output like this:

commit 69b6309f09365c09a2fe10f09aee801d1fae29ee (HEAD -> master, edeviserBranch)
Author: eDeviser <[email protected]>
Date:   Mon Sep 2 09:53:07 2019 +0200

    added foo

commit 59a08270fb730db259a8d5819bb585a613024d97 (origin/master, origin/HEAD)
Author: eDeviser <[email protected]>
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?

like image 629
eDeviser Avatar asked Sep 02 '19 08:09

eDeviser


People also ask

What information is shown in the git log?

The git log command shows a list of all the commits made to a repository. You can see the hash of each Git commit , the message associated with each commit, and more metadata. This command is useful for displaying the history of a repository.

What is git log -- Oneline?

Git Log OnelineThe oneline option is used to display the output as one commit per line. It also shows the output in brief like the first seven characters of the commit SHA and the commit message. It will be used as follows: $ git log --oneline.

What are the 40 character strings of letters and numbers that appear in git log called?

"SHA" stands for Simple Hashing Algorithm. The checksum is the result of combining all the changes in the commit and feeding them to an algorithm that generates these 40-character strings. A checksum uniquely identifies a commit.

How do I view git logs?

The command for that would be git log –oneline -n where n represents the number up to which commit you to want to see the logs.


1 Answers

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.

like image 189
mfnx Avatar answered Sep 21 '22 01:09

mfnx