tags:

views:

38

answers:

1

I used filter-branch to fix an incorrect email address in my repository but all the branches are now MIA (except master).

This is what git graph showed prior to filter-branch:

*   d93c7ee (HEAD, master) Merge branch 'f1'
|\  
| * 08e7463 (f1) adding b
|/  
* 7c7bd91 adding a

I issued this filter-branch command:

git filter-branch --env-filter 'export GIT_AUTHOR_EMAIL="fixed-email";
                                GIT_AUTHOR_NAME="fixed-author"'

And got this:

*   770262a (HEAD, master) Merge branch 'f1'
|\  
| * 0f58ab5 adding b
|/  
* fb012a9 adding a
*   d93c7ee (refs/original/refs/heads/master) Merge branch 'f1'
|\  
| * 08e7463 (f1) adding b
|/  
* 7c7bd91 adding a

A few things that bother me:

1) f1 branch wasn't moved to 0f58ab5.
2) All commits before fb012a9 seem irrelevant to me, can I get rid of them?

I saw in another question someone suggesting to:

rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --aggressive --prune=now

But it didn't quite help, this is what I got afterwards:

*   770262a (HEAD, master) Merge branch 'f1'
|\  
| * 0f58ab5 adding b
|/  
* fb012a9 adding a
* 08e7463 (f1) adding b
* 7c7bd91 adding a

EDIT: doing what VonC had suggested yielded this graph:

*   211632d (HEAD, master) Merge branch 'f1'
|\  
| * bda7577 (f1) adding b
|/  
* 70c7b34 adding a
*   3182b33 (refs/original/refs/heads/master) Merge branch 'f1'
|\  
| * 8b81c21 (refs/original/refs/heads/f1) adding b
|/  
* 4c07dc9 adding a

Which solved problem #1, now I only need to find a way to get rid of the old commits, how do I accomplish that?

+1  A: 

Could you try again your git filter-branch with a '-- --all' at the end, like:

git filter-branch --env-filter 'export GIT_AUTHOR_EMAIL="fixed-email";
                                       GIT_AUTHOR_NAME="fixed-author"' -- --all

Note:

  • the -- that separates filter-branch options from revision options,
  • and the --all to rewrite all branches and tags.

That said, in your current situation, no amount of git gc ... prune ... will remove a commit which is still referenced by a branch marker, like f1 which still points to 08e7463.
So what you are seeing is normal, by design.


The OP reports that, once doing the git filter-branch ... -- --all, a rm -r .git/refs/original takes care of the old commits.

Again, this is not surprising: no tag or branch reference them anymore, meaning this time, their are candidate for a permanent removal from the Git repo.

VonC
thanks, it solved one of the problems, see my edit.
Idan K
actually `rm -r .git/refs/original` did do the trick this time, weird... thanks!
Idan K
@Idan: thank you for your feedback. I have completed my answer with it.
VonC