GIT - How to know the branch a branch branched from?

前端 未结 4 580
广开言路
广开言路 2021-01-11 15:19

Support I create multiple branches (aaa, bbb, ccc) from a commit. Then, I create a new branch (ffffd) from one of the branch (bbb) and a make a commit on it.

Then I p

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-11 16:06

    add those two functions to your .bashrc:

    function newbranch() {
        history_file=".git/branching_history"
        from=`git rev-parse --abbrev-ref HEAD`
        to=$1
        git checkout -b $1 > /dev/null 2>&1
        DATE=`date '+%Y-%m-%d %H:%M:%S'`
        echo "$DATE: from $from created branch $1" >> $history_file
    }
    
    function branchinghistory() {
        cat .git/branching_history
    }
    

    then when you create a new branch, don't run git checkout -b mybranch but do:

    newbranch mybranch

    this will store your branching log in .git/branching_history file. You can check the log with:

    branchinghistory

    the output should be:

    2020-04-22 23:59:06: from master created branch mybranch

提交回复
热议问题