我希望在我的项目的第一次提交中更改某些内容而不会丢失所有后续提交.有没有办法做到这一点?
我不小心在源代码中的评论中列出了我的原始电子邮件,我想改变它,因为我从机器人索引GitHub收到垃圾邮件.
有办法从以后的提交中更改消息:
git commit --amend # for the most recent commit
git rebase --interactive master~2 # but requires *parent*
Run Code Online (Sandbox Code Playgroud)
如何更改第一次提交(没有父级)的提交消息?
在最后一个小时左右,我修改了文件
A
ATest
B
BTest
Run Code Online (Sandbox Code Playgroud)
为了确保我的提交消息与实际更改对齐A,使用描述进行提交.不幸的是,我没有参与ATest该提交.
与此同时,仍然没有承诺B和BTest.
在这一点上,最好的方法是什么?我想要:
让我们说你在终端,目前坐在git repo的根源.
如果你已经安装了GitPython,你可以这样做以获得最后一次提交的提交,或者更确切地说,是HEAD指向的提交:
>>> import git
>>> r = git.Repo('.')
>>> c = r.head.commit
>>> c
<git.Commit "62e71e8210d0d0275b1f5845bf3033a7bfa3ed73">
>>> c.message
u'old message'
>>> c.message = "new message"
>>> c.message
'new message'
Run Code Online (Sandbox Code Playgroud)
但是如果退出python并进入git log此处,您将看到提交消息保持不变.如何编辑此库的提交?
我创建了一个提交,其中包含要修改的提交消息。我还没有发布提交,所以我可以安全地重写历史。我可以使用 git log 找到,所以我知道它的 sha1 哈希值。如何快速编辑提交?