3

I wanted to change the details of committer of previous commits. Porblem is when I tried to change, I see duplicate commits with from both user name.

Here is the full story. I created a repository on GitHub. I cloned that repo on my machine with git clome command. I had recently formatted machine, however I copied SSH keys from old machine and I thought it would work (I did not know about setting up git config command). I started working on project, made some commits. When I saw why my commits are not showing on github contributions, I saw in commiiter details that it was not considering my GitHub user details. I googled up and saw this solution and ran the same, running on master (instead of HEAD).

Now I see duplicate commits, same commit message from both username. Here is the screenshot :

enter image description here

I do have back up of whole thing before I tried to run the script.

  1. Did I do any mistake in running that command? If yes, I can try running it on my back up copy. If it fixes the problem, then how do I push it on github?

  2. Now with the current one, which has duplicate commit details, how do I remove them and fix it?

Following is the command I ran from that link:

git filter-branch --commit-filter '
        if [ "$GIT_COMMITTER_NAME" = "avi" ];
        then
                GIT_COMMITTER_NAME="avinassh";
                GIT_AUTHOR_NAME="avinassh";
                GIT_COMMITTER_EMAIL="email which I use for GitHub";
                GIT_AUTHOR_EMAIL="email which I use for GitHub";
                git commit-tree "$@";
        else
                git commit-tree "$@";
        fi' HEAD
Community
  • 1
  • 1
avi
  • 9,292
  • 11
  • 47
  • 84

2 Answers2

2

This happened to me just now. What I did wrong was after updating the remote GitHub repository I did not create a new clone of it, rather continued to use the old one which still included the commits with old names. Once I have pushed from this old clone, the old commits were pushed and now there are duplicates.

If you have a backup of the repository before the rename, I think it is easier to get started again from the backup, just be careful not to repeat the same mistake - any repositories which are already cloned (by you or anyone else) need to deleted and cloned again after you manipulate their history.

I have also tried switching to the repository instead using TortoiseGit Switch/Checkout command (corresponds to git.exe checkout master -- command), and it seems to work as well, but you definitely need to make sure all cloned repositories are updated to match the remote version somehow, otherwise they will break it once you push from them.

As I was not careful enough to have a backup, this is what I have done to fix it:

In my case the history repeated two sets of identical commits, starting with the first commit which was manipulated by the script. I copied the SHA of the last commit before the first duplicate and performed git reset <sha> followed to git push --force. Then I made sure all existing clones are deleted and cloned again.

Suma
  • 33,181
  • 16
  • 123
  • 191
1

Used GitHub's official script and it worked like charm. I used the script on clone copy of original repo which had two usernames. Then I did a force git push. Everything seems fine!

avi
  • 9,292
  • 11
  • 47
  • 84