preface

Tick tick tick, look up at the clock on the wall, it’s one o ‘clock in the morning. Xiao Ming finally finished his notes on the second chapter of the Go Language Bible. He saved the commit and went to sleep. Well, wait a minute, no, xiao Ming found that he used the company’s Git account, git log, the latest commit Author information is the company’s email address, embarrassed, does Xiao Ming need to write again? “Don’t ~”, Xiao Ming crazy to.

Suddenly, the screen pauses, and Dr. Git steps out of the background. It turns out to be a movie. Dr. Git said, “Students, what should you do if you encounter this case?” “Then,” Don’t panic. Git Rebase will take care of it.”

The body of the

Take a look at Xiao Ming’s log first

$git log
commit 34da55544be6ceb1269e24b921275b4a771 (HEAD -> main, origin/main, origin/HEAD)
Author: Company <[email protected]>
Date:   Mon Jun 8 01:51:52 2021 +0800

    commit 3

commit 98f419726756cba7923e3c0062bd1231d25
Author: Ming <[email protected]>
Date:   Mon Jun 7 20:09:48 2021 +0800

    commit 2

commit 15f0d5882db5dedee737a90e3df98bd395
Author: Company <[email protected]>
Date:   Sat May 15 16:34:06 2021 +0800

    commit 1
Copy the code

The Author Company

for commit 1 and commit 3 is Ming

. The Author Company

for commit 1 and commit 3 is Ming
@ming.com>
@company.com>
@ming.com>
@company.com>

Modify the Author information of the last commit

$git commit --commit --author="Ming <[email protected]>"
Copy the code

Enter an interactive page similar to the Vim editor

commit 3
  
# Please enter the commit message for your changes. Lines starting
# with The '#' will be ignored, and an empty message aborts the commit.
#
# Author: ming 
       @ming.com>
#Date: Mon Jun 7 22:05:18 2021 +0800
#
# On branch master
#
# On branch main
#
# Changes to be committed:
#new file: ...
#
Copy the code

Save and exit.

Modify the Author information of previous commit

Enter the following command. The -i parameter indicates the interaction mode

git rebase -i HEAD~3
Copy the code

Go to an interactive page similar to the Vim editor and change the pick at the beginning of commit 1 to Edit

edit acdaa07 commit 1
pick 2f30e03 commit 2
pick 34da555 commit 3

#Rebase b94735d.. 34da555 onto b94735d (3 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
Copy the code

Then save and exit, namely :wq, and output the following information:

You can amend the commit now, with

    git commit --amend 

Once you are satisfied with your changes, run

    git rebase --continue
Copy the code

Then enter the following command to modify the submitter information

$git commit --amend --author="Ming <[email protected]>"
Copy the code

Finally, enter the save command

$git commit --continue
Successfully rebased and updated refs/heads/master.`
Copy the code

Let’s look at Xiao Ming’s log again

$git log
commit 34da55544be6ceb1269e24b921275b4a771 (HEAD -> main, origin/main, origin/HEAD)
Author: Ming <[email protected]>
Date:   Mon Jun 8 01:51:52 2021 +0800

    commit 3

commit 98f419726756cba7923e3c0062bd1231d25
Author: Ming <[email protected]>
Date:   Mon Jun 7 20:09:48 2021 +0800

    commit 2

commit 15f0d5882db5dedee737a90e3df98bd395
Author: Ming <[email protected]>
Date:   Sat May 15 16:34:06 2021 +0800

    commit 1
Copy the code

Done, Xiao Ming can finally wash to sleep, tomorrow today is a good day to wake up ~