圖文詳解如何修改git已提交記錄的郵箱?

有時候,公司提交的代碼必須使用公司郵箱,而你誤操做,直接把本身我的郵箱提交上去了,此時你就會遇到這樣的需求:如何修改git已提交的郵箱?git

而這個需求對於新手來講,每每要花費半天的時間才能理解修改過程,簡直太傻比了,因此我這裏作一個詳細的文檔來幫助本身和你搞清楚這個流程。尤爲要理解變基,它不是一個命令執行就完成了,而是一連串命令的組合。shell

變基

git rebase -i

執行後,會打開最近一條的提交記錄,固然上面的命令能夠指定某一條記錄,命令是:編輯器

git rebase -i "your commit id"

對於sourcetree用戶來講,commit id是SHA-1,能夠右鍵某條提交記錄,選擇菜單"複製SHA-1到剪貼板",以下圖:this

image-20190513113342522

變基rebase命令執行完成後,會打印相似以下內容:rest

pick bd81df5 更新API

# Rebase abcb9d0..bd81df5 onto abcb9d0 (1 command)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

新手每每會一臉懵逼,不止所錯,此時是在rebase的過程當中,你須要把pick改成edit,以下:code

edit bd81df5 更新API

# Rebase abcb9d0..bd81df5 onto abcb9d0 (1 command)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

更改完成後,保存並退出vi編輯器::wqserver

而後會打印這樣的消息:blog

chengmingdeMacBook-Pro:server cmlanche$ git rebase -i "abcb9d0d1e99cdad25d8d08119e494436b000e59"
Stopped at bd81df5...  更新API
You can amend the commit now, with

  git commit --amend 

Once you are satisfied with your changes, run

  git rebase --continue
chengmingdeMacBook-Pro:server cmlanche$

給你們先科普一下這個amend英文單詞,是修改的意思,對我來講好陌生,爲啥不用change或者fix之類的。rem

image-20190513114137949

上面的信息說了,若是你要amend,也就是要修改這個提交的話,那麼用文檔

git commit --amend

若是你對此次修改滿意的話,就用以下命令結束這次變基

git rebase --continue

重置帳戶郵箱信息

咱們固然要修改啦,那麼執行以下命令,重置提交的帳戶信息:

git commit --amend --author="cmlanche <1204833748@qq.com>" --no-edit

同事,要注意你的sourcetree,出現了新狀況!

image-20190513114851415

咱們能夠看到一個新的提交,而且,郵箱帳號都通過了修改,若是你去掉--no-edit還能夠修改commit message,也就是圖中的"更新API",舉栗子吧,我能夠繼續用amend修改這次變基

git commit --amend --author="cmlanche <1204833748@qq.com>"

image-20190513115132114

保存退出vi編輯器,看sourcetree咋樣了:

image-20190513115216969

真的很完美,接下來就是合併了,退出變基。

退出變基

git rebase --continue

在控制檯中打印如上命令退出變基,咱們看到退出變基也就是使用最新的修改了,就一條分支了。

chengmingdeMacBook-Pro:server cmlanche$ git rebase --continue
Successfully rebased and updated refs/heads/bulma.

image-20190513115442779

最後總結一下

變基真的頗有用,他不是一條命令搞定的,是一個過程,就像變成中打開了一個輸入流,最後用完你得關閉輸入流同樣。

經過變基你能夠輕鬆實現提交信息的任意從新修改!

相關文章
相關標籤/搜索