日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

如何修改git已提交记录的邮箱?

發(fā)布時間:2025/6/17 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 如何修改git已提交记录的邮箱? 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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

而這個需求對于新手來說,往往要花費(fèi)半天的時間才能理解修改過程,簡直太傻比了,所以我這里做一個詳細(xì)的文檔來幫助自己和你搞清楚這個流程。尤其要理解變基,它不是一個命令執(zhí)行就完成了,而是一連串命令的組合。

變基

git rebase -i 復(fù)制代碼

執(zhí)行后,會打開最近一條的提交記錄,當(dāng)然上面的命令可以指定某一條記錄,命令是:

git rebase -i "your commit id" 復(fù)制代碼

對于sourcetree用戶來說,commit id是SHA-1,可以右鍵某條提交記錄,選擇菜單"復(fù)制SHA-1到剪貼板",如下圖:

變基rebase命令執(zhí)行完成后,會打印類似如下內(nèi)容:

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 復(fù)制代碼

新手往往會一臉懵逼,不止所錯,此時是在rebase的過程中,你需要把pick改為edit,如下:

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 復(fù)制代碼

更改完成后,保存并退出vi編輯器::wq

然后會打印這樣的消息:

chengmingdeMacBook-Pro:server cmlanche$ git rebase -i "abcb9d0d1e99cdad25d8d08119e494436b000e59" Stopped at bd81df5... 更新API You can amend the commit now, withgit commit --amend Once you are satisfied with your changes, rungit rebase --continue chengmingdeMacBook-Pro:server cmlanche$ 復(fù)制代碼

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

上面的信息說了,如果你要amend,也就是要修改這個提交的話,那么用

git commit --amend 復(fù)制代碼

如果你對這次修改滿意的話,就用如下命令結(jié)束此次變基

git rebase --continue 復(fù)制代碼

重置賬戶郵箱信息

我們當(dāng)然要修改啦,那么執(zhí)行如下命令,重置提交的賬戶信息:

git commit --amend --author="cmlanche <1204833748@qq.com>" --no-edit 復(fù)制代碼

同事,要注意你的sourcetree,出現(xiàn)了新情況!

我們可以看到一個新的提交,并且,郵箱賬號都經(jīng)過了修改,如果你去掉--no-edit還可以修改commit message,也就是圖中的"更新API",舉栗子吧,我可以繼續(xù)用amend修改此次變基

git commit --amend --author="cmlanche <1204833748@qq.com>" 復(fù)制代碼

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

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

退出變基

git rebase --continue 復(fù)制代碼

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

chengmingdeMacBook-Pro:server cmlanche$ git rebase --continue Successfully rebased and updated refs/heads/bulma. 復(fù)制代碼

最后總結(jié)一下

變基真的很有用,他不是一條命令搞定的,是一個過程,就像變成中打開了一個輸入流,最后用完你得關(guān)閉輸入流一樣。

通過變基你可以輕松實(shí)現(xiàn)提交信息的任意重新修改!

轉(zhuǎn)載于:https://juejin.im/post/5cd8f73df265da038932b2fc

《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

總結(jié)

以上是生活随笔為你收集整理的如何修改git已提交记录的邮箱?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。