Git - Duplicate commit issue
Asked Answered
J

2

10

I accidentally created commits by "unknown" in my repository, and decided to try running a command from here:

git filter-branch --commit-filter '
        if [ "$GIT_COMMITTER_NAME" = "unknown" ];
        then
                GIT_COMMITTER_NAME="..";
                GIT_AUTHOR_NAME="..";
                GIT_COMMITTER_EMAIL="...";
                GIT_AUTHOR_EMAIL="...";
                git commit-tree "$@";
        else
                git commit-tree "$@";
        fi' HEAD

At first I thought everything was fine, until I noticed in gitk that every commit prior to running this was duplicated, not simply edited as I originally thought.

Is it possible to clean this up?

EDIT: OK, gitk is showing both the old commits (the ones with the "unknown" commiters mixed in) and the new commits (the rewritten ones), split up at a certain point around halfway. Think a bunch of commits, then duplicated (and with the edits), and stacked on top of the original ones. What I want to do is if possible, is remove the original ones.

Justino answered 30/12, 2009 at 23:37 Comment(4)
Let's see if I'm getting this: do you have a commit tree that looks like ...--a--b--c--(*)--a'--b'--c'--d--e, where (*) is the commit on which you ran the bad command, [abc]' are erroneously duplicated commits you want to delete, and [de] are commits you want to keep?Captivate
Well, it's more complicated due to branching, but basically as you said, but I want to keep the ' ones as they have the author fields fixed.Justino
Okay, so you want to delete [abc], but keep [abc]'?Captivate
Yes, I want to delete my original commits.Justino
J
7

The answer was the files in .git/refs/original, and how the command I found should not have ended in HEAD but instead with --tag-name-filter cat -- --all.

Cheers to _Vi and wereHamster from the #git channel for the help.

Justino answered 31/12, 2009 at 4:46 Comment(0)
C
1

If you know the last good commit, save your bacon with this:

git reset <last_good_commit>   # Warp back to a good state.
git push -f master             # Push the changes up (you need -f to force it to
                               #  obliterate old commits).

If you want to tread more carefully (for example, if there are good and bad commits mixed in after <last_good_commit>), use git rebase -i to cherry-pick the good ones that should stay behind.

Captivate answered 31/12, 2009 at 0:0 Comment(1)
I'm not very familiar with the command line, and I'm not sure what cherry picking or rebasing are... also, I've added a clarification on what I want to do.Justino

© 2022 - 2024 — McMap. All rights reserved.