1

I have a very large repo which needs some clean up. The repo came from SVN and was messy to begin with.

There are many branches, some of them were merged into trunk, while others were not. Unfortunately, SVN did not track this so merged/unmerged branches from SVN look the same. (as Branches just hanging out there in the wind)

I would like to trim off these extraneous branches and clean things up a bit.

How can I take the SHA1 of a commit, and compare ONLY the changes that occured in that commit with what is in master? (Thus if all the changes in the commits for a certain branch are in master, I can delete the branch, otherwise I can maintain the branch appropriately).

Example of the Tree:

           o--o--o--o--o Unmerged from SVN
          /
o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o Master
    \                             \         /
     o--o--o Merged from SVN        o--o--o 

(note how two branches are NOT merged back into master as far as Git knows, but in one of them, all of the changes are in master because it was merged while it was an SVN repo, this one I want to delete)

Toymakerii
  • 1,510
  • 2
  • 12
  • 26
  • 1
    Not sure from a SVN imported repo but I have used git log .. to see if the branch is included and thus could be deleted. I should have said - it will produce no results if it has been merged. – Adrian Cornish Aug 17 '12 at 00:44
  • Right, it is also possible to use git remote prune which will remove any branch that has been merged (obviously on the remote server). However these are dangling branches. – Toymakerii Aug 17 '12 at 12:43

2 Answers2

2

Try merge a branch anyway:

git merge --no-commit  YourDanglingBranch

This will try to merge YourDanglingBranch but don't actually do the commit.

If YourDanglingBranch is already merged, git is smart enough to do nothing in my test. So just use git merge --abort to finish this branch, delete it safely and proceed with another.

If YourDanglingBranch hasn't been merged, a merge is done without commit. You can examine the changes, resolve the possible conflict, and then commit the merged version.

Penghe Geng
  • 13,286
  • 5
  • 31
  • 40
1

Do the branches have divergent hashes? If not, just run git checkout master && git branch -d <branch> and be done with it. With the lowercase -d flag, git will refuse to delete a branch that isn't merged into the checked out branch (in this example, master, but it could be any branch of your choosing).

In fact, you could just automate this easily. This answer shows a git alias that will delete any branch not merged with the current branch. It's a bit terrifying to watch it work, but it works just fine.

Community
  • 1
  • 1
Christopher
  • 42,720
  • 11
  • 81
  • 99