我想知道如何在sourcetree中撤消git提交或重命名提交消息。我使用错误的提交消息提交了我的更改。我想要撤消该提交,并将其从图中删除。我已经尝试了反向提交选项,但它在图中显示了另一个提交。
发布于 2018-06-03 15:32:04
我现在想象一下,您试图使用git revert
撤消提交,但它以额外的提交结束了您,这是一个为您提供的解决方案。使用git log --oneline'
向你展示你的日志,你会发现提交错误的消息,除此之外,你会发现它的散列(像53fnd3w
),复制它然后输入
git reset --hard <paste-the-hash>
这将引导您返回到那个提交,在此之后,如果您只想更改提交使用的名称
git commit --amend -m "New commit message"
这将使您更改最近提交的名称,但如果您想要撤消这些更改,因为您想要将它们划分为两个提交或其他东西,请使用
git reset HEAD^
这将返回当前未提交更改的前一次提交,一旦您进行新的提交,它将忽略HEAD^
之后的提交,并且当您进行新的提交时,您将只看到新的提交
git log --oneline
希望这能有所帮助
发布于 2018-06-04 08:49:31
一个非常有用的“重写历史”命令: rebase
你需要指定一个参考点(历史上最后一次Ok提交),它是这样的:
git rebase -i <reference point sha/tag/branch>
这将引导您进入提交列表,并允许您使用以下选项修改它们
#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
我认为'r‘就是你想要的,但你可以看到它的功能要强大得多。git doc on rewriting history。
在此之后,您将需要执行强制推送来更新远程服务器
git push -f <remote> <branch>
https://stackoverflow.com/questions/50667772
复制