Custom git log command
Add the following line to your ~/.bashrc
would provide
gl
command for printing pretty git-log
output.
alias gl='git log --graph --pretty=format:"%Cred%h%Creset . %an: %s %Cgreen(%cr)%Creset" --abbrev-commit --date=relative'
When gl
command is executed, an output look like the following would be generated:
* 11a76be . Liangfu Chen: fix problem #26; (5 days ago) * d375136 . Liangfu Chen: fix problem #31; (5 days ago) * 9d3f1de . Liangfu Chen: Merge branch 'master' of blah ... (5 days ago) |\ | * c254636 . blah ... (6 days ago) | |\ | * | 9e2f1a4 . blah ... (6 days ago) * | | a24bf14 . Liangfu Chen: fix problem 29; (5 days ago) | |/ |/| * | 1b13634 . Liangfu Chen: blah ...
Undo a commit and redo
A post on SO
explains how to undo previous git commit
.
$ git commit -m "Something terribly misguided" (1)
$ git reset --soft HEAD~1 (2)
# << edit files if necessary >> (3)
$ git add ... (4)
$ git commit -c ORIG_HEAD (5)
Say, there are three cases:
- previous commit is a disaster, then reset with argument --hard to REMOVE the file changes. (This can be dangerous if your file changes are important!!)
- previous commit is a NOT disaster, just undo the commit but keep the changes, then reset WITHOUT argument --hard or --soft to keep the file changes.
- previous commit is a NOT disaster, in case you might needed it after all, then reset with argument --soft to keep the file changes and the index.
Renamed a branch and create new branch
First, we need to switch to another branch to rename the current one:
$ git checkout testing
To rename a branch, e.g. rename master branch to a date:
$ git branch -m master master-r`date +%F`
Then create a brand new branch, to replace the previous master branch:
$ git checkout --orphan master
the --orphan
argument generates an empty branch, instead of the current one.
And finally, pull remote content to current master branch, which would not lead to any conflict, obviously.
$ git pull origin master
comments powered by Disqus