简体   繁体   中英

Git - detect if branch has no changes after rebase

Is there any tool/trick to improve this workflow:

⋊> on master ◦ git branch -d add_code_to_import_from_mew       
error: The branch 'add_code_to_import_from_mew' is not fully merged.
If you are sure you want to delete it, run 'git branch -D add_code_to_import_from_mew'.

⋊> on master ◦ git checkout add_code_to_import_from_mew                                               Switched to branch 'add_code_to_import_from_mew'

⋊> on add_code_to_import_from_mew  git rebase master 
First, rewinding head to replay your work on top of it...

⋊> on add_code_to_import_from_mew  git checkout master                                            21:13:22
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.

⋊> on master ◦ git branch -d add_code_to_import_from_mew                                          21:13:33
Deleted branch add_code_to_import_from_mew (was ed05c05).

I do not want to use "-D" - just want to delete when there are no changes

The following (POSIX-compliant) script will delete all local branches that have empty diffs against master :

#!/usr/bin/env sh

git for-each-ref --format='%(refname:short)' refs/heads | \
  while read ref; do
    test $ref != master && \
      git diff-tree --quiet $ref master && \
      git branch -D $ref
  done

Use with caution! An empty diff with master doesn't imply that the branch is fully merged in master !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM