Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
433 views
in Technique[技术] by (71.8m points)

git - 如何更改一个特定提交的提交作者?(How to change the commit author for one specific commit?)

I want to change the author of one specific commit in the history.

(我想更改历史记录中一项特定提交的作者。)

It's not the last commit.

(这不是最后一次提交。)

I know about this question - How do I change the author of a commit in git?

(我知道这个问题- 如何在git中更改提交的作者?)

But I am thinking about something, where I identify the commit by hash or short-hash.

(但是我正在考虑某些事情,在这里我通过哈希或短哈希来标识提交。)

  ask by MicTech translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Interactive rebase off of a point earlier in the history than the commit you need to modify ( git rebase -i <earliercommit> ).

(交互式重新定位在历史记录中比您需要修改的提交更早的一点( git rebase -i <earliercommit> )。)

In the list of commits being rebased, change the text from pick to edit next to the hash of the one you want to modify.

(在要重新提交的提交列表中,将文本从pick更改为您想要修改的哈希旁边的edit 。)

Then when git prompts you to change the commit, use this:

(然后,当git提示您更改提交时,请使用以下命令:)

git commit --amend --author="Author Name <[email protected]>"

For example, if your commit history is ABCDEF with F as HEAD , and you want to change the author of C and D , then you would...

(例如,如果您的提交历史记录是ABCDEFFHEAD ,并且您想更改CD的作者,那么您将...)

  1. Specify git rebase -i B ( here is an example of what you will see after executing the git rebase -i B command )

    (指定git rebase -i B这是执行git rebase -i B命令后将看到的示例 ))

    • if you need to edit A , use git rebase -i --root

      (如果您需要编辑A ,请使用git rebase -i --root)

  2. change the lines for both C and D from pick to edit

    (将CDpick更改为edit)

  3. Once the rebase started, it would first pause at C

    (重新启动基准后,它将首先在C暂停)

  4. You would git commit --amend --author="Author Name <[email protected]>"

    (您将git commit --amend --author="Author Name <[email protected]>")

  5. Then git rebase --continue

    (然后git rebase --continue)

  6. It would pause again at D

    (它会在D再次暂停)

  7. Then you would git commit --amend --author="Author Name <[email protected]>" again

    (然后,您将再次git commit --amend --author="Author Name <[email protected]>")

  8. git rebase --continue
  9. The rebase would complete.

    (重新设置将完成。)

  10. Use git push -f to update your origin with the updated commits.

    (使用git push -f使用更新的提交来更新源。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...