Git - Duplicate commit issue
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_CO开发者_如何学JAVAMMITTER_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.
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.
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.
精彩评论