2

How can I alter/delete commit history?

I have been working on a project from my home computer, where git config user.name was different than the one at office. I do not want the nicks to mingle. I have already pushed the code to the official repository.

In the commit history as of now, I have the logs as: committed by "my_home_nick"

But I want all of the commit messages to appear as: committed by "my_office_nick"

Is there anyway of doing it?

In short say there are logs: committed by x

I want that to change to committed by y

Benjol
  • 63,995
  • 54
  • 186
  • 268
user993563
  • 18,601
  • 10
  • 42
  • 55
  • 1
    You should consider rewording your question's title... I think by "deleting commit history" you really mean "alter commit history". They're pretty different things. – user229044 Dec 06 '11 at 14:51

4 Answers4

2

Yes, look at the git filter-branch command. It will rewrite the history as you need.

Keep in mind, that it will create a new history. Creating new history and making the branch point to it is called a "rewind" in git and also happens if you use more common commands like git rebase. It is fine as long as nobody based their work on the old history, but if they did, it will cause a lot of confusion. Existing history, being identified by it's SHA1 hash, is immutable.

Jan Hudec
  • 73,652
  • 13
  • 125
  • 172
2
git filter-branch --commit-filter '
        if [ "$GIT_COMMITTER_NAME" = "your_home_nick" ];
        then
                GIT_COMMITTER_NAME="your_office_nick";
                GIT_AUTHOR_NAME="Office Name";
                GIT_COMMITTER_EMAIL="office@email.com";
                GIT_AUTHOR_EMAIL="author@email.com";
                git commit-tree "$@";
        else
                git commit-tree "$@";
        fi' HEAD
whatf
  • 6,378
  • 14
  • 49
  • 78
0

You can use one or more of following options

  1. You can squash / reorganize commits using command git rebase --interactive

  2. If you have not pushed changes to official repository using my_home_nick, you can create another clone and pull / merge changes with correct user name

  3. You can use git filter-branch to fix committer name

Benjol
  • 63,995
  • 54
  • 186
  • 268
forvaidya
  • 3,041
  • 3
  • 26
  • 33
0

Here is the same question with many answers.

You say you pushed to the "official repository", but if you are not the only commiter to this repository and somebody already pulled incorrect commits or, worse, based some changes on top of your commits, leaving incorrect commiter name will cause mush less confusion then altering history, because git really doesn't allow changing commits, it only allows creating alternative history in place of incorrect, as Jan Hudec wrote already.

Community
  • 1
  • 1
Valentin Nemcev
  • 4,940
  • 2
  • 20
  • 21