Showing posts with label Git. Show all posts
Showing posts with label Git. Show all posts

Thursday, March 3, 2016

Remove all merged local branches in Git except master


$ git branch
  a
  b
  c
* master

Here, branch 'c' has not merged with master yet. Let's remove all merged branches:

$ git branch --merged master | grep -v master | xargs git branch -d
Deleted branch a (was ebb9040).
Deleted branch b (was ebb9040).

$ git branch
  c
* master

Wednesday, April 1, 2015

Git: undo the last rebase

$ git reflog

f0d821f HEAD@{0}: commit_a
2ea24f8 HEAD@{1}: commit_b
0c3cd49 HEAD@{2}: commit_c
de5b02a HEAD@{3}: commit_d

Suppose that "commit_c" was the head commit of the branch just before the rebase. Let's reset the current branch to this commit:

$ git reset --hard HEAD@{2}

Friday, January 23, 2015

Hash mark in git commit message

 From the git commit message:

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.


So, if you want to use a hash mark '#' in the commit message (E.g.: "#77 - fixed by changing user's permissions") use the following form of commit:

git commit --cleanup=whitespace

NOTE: don't forget to remove other unnecessary lines which start with '#' otherwise they will be added to the commit message as well