How to modify the author's information git commit

When there are multiple local git accounts, projects likely to forget to set the default account, the last case of a global account to submit, in fact, had no effect on the code itself, just submit records show that in the name of another slightly awkward.

For example:   to see the commit log, assumed that a ([email protected]) submitted three times, found user submitted wrong, the user should be presented with b:

$ git log
# 输出如下
commit 3 (HEAD -> branch1)
Author: a <[email protected]>
Date: Thu Nov 22 16:22:59 2018 +0800
commit 3
commit 2 (HEAD -> branch1)
Author: a <[email protected]>
Date: Thu Nov 22 16:22:59 2018 +0800
commit 2
commit 1 (HEAD -> branch1)
Author: a <[email protected]>
Date: Thu Nov 22 16:22:59 2018 +0800
commit 1


First, how to reset the user information of the project :

$ git config user.name 'b'
$ git config user.email [email protected]

 

Second, use the command to modify commit amend information (Note: amend command will only modify the information of the last commit, commit before requires the use of rebase)

$ git commit --amend --reset-author

 

Third, if you need to modify history information submitted by rebase operation

Git rebase -i the HEAD ~ $ 3        // this command if error, please turn my blog, there is a workaround

# output as
pick the commit 1 1
pick the commit 2 2
pick 3 3 the commit
you want to modify what, put the pick that line changed edit, and then exit. For example, want to change the commit author 1, the cursor to the first pick, i press enter INSERT mode, the pick to edit:

1 commit 1 Edit
Pick the commit 2 2
Pick 3 the commit 3
...
- INSERT -
then press esc to exit INSERT mode, enter: wq exit, then you can see the prompt, you can modify the information of the commit 1:

Command resets the user information input amend:   $ Git-author the commit --amend --reset

1 will commit the record and comment content, enter INSERT mode change comments,: wq exit.

The next time you view your history found commit author 1 has become b ([email protected]), the date and time is recorded.

Continue back to normal by the command:  $ git rebase --continue

 

Guess you like

Origin www.cnblogs.com/651434092qq/p/11015901.html