Tag Archives: git

git terminal graph with branch names

I have searched several times how to produce graph tree in terminal similar to Gitk or other GUI visualizers. Compiling the knowledge in this StackOverflow question together, I came up with the following command:

git log --graph --full-history --all --color --date=short --pretty=format:"%x1b[31m%h%x09%x1b[0m%x20%ad%x1b[32m%d%x1b[0m %s %x1b[30m(%an)%x1b[0m"

UPDATE: I added annotation to the end of line in dark-grey (not shown in the image) so that you can blame people quicker.

This produces graph shown on the image.

GIT graph in terminal

GIT graph in terminal with branch names

If you noticed, I have aliased all of this for a much shorter command git tree, which can be done with the following git config line:

git config --global alias.tree 'log --graph --full-history --all --color --date=short --pretty=format:"%x1b[31m%h%x09%x1b[0m%x20%ad%x1b[32m%d%x1b[0m %s %x1b[30m(%an)%x1b[0m"'

Notice the two sets of quatation marks.

Git reset –merge

Or how to reset a merge commit?

If just after a merge commit you recognized that it was actually “git rebase” that you wanted to do, then your friend is:

git reset –merge 14c1d90c3e

where the target commit is the one preceding the merge.

But when reset is not an option?

But if you found the faulty merge after several other commits (or after pushing to remotes), resetting is not so good idea or won’t work at all. In that case refer to How to Revert Faulty Merge in the HowTo.