我在承诺信中写错了。
我怎么能改變訊息呢?承諾尚未推動。
我在承诺信中写错了。
我怎么能改變訊息呢?承諾尚未推動。
当前回答
使用
git commit --amend
要详细理解,一个很好的帖子是 4. 重新写 Git 历史. 它也谈论什么时候不使用 git commit --amend。
其他回答
如果你只是想编辑最新的承诺,使用:
git commit --amend
或
git commit --amend -m 'one line message'
但是,如果你想连续编辑多个命令,你应该使用重定向,而不是:
git rebase -i <hash of one commit before the wrong commit>
此分類上一篇
在文件中,如上面的文件中,输入编辑或其他选项之一,然后点击保存和输出。
现在你将处于第一个错误的承诺,在文件中进行更改,它们将自动为你排列。
git commit --amend
保存和输出这个和类型
git rebase --continue
移动到下一个选择,直到完成所有的选择。
请注意,这些事情在这个特殊的承诺之后改变了您的所有SHA<unk>。
更新您的最后一个错误的承诺消息与新的承诺消息在一个行:
git commit --amend -m "your new commit message"
或者,尝试 Git 重新设置如下:
# You can reset your head to n number of commit
# NOT a good idea for changing last commit message,
# but you can get an idea to split commit into multiple commits
git reset --soft HEAD^
# It will reset you last commit. Now, you
# can re-commit it with new commit message.
使用重新设置将命令分成较小的命令
git 重新设置可以帮助您将一个承诺分成多个承诺:
# Reset your head. I am resetting to last commits:
git reset --soft HEAD^
# (You can reset multiple commit by doing HEAD~2(no. of commits)
# Now, reset your head for splitting it to multiple commits
git reset HEAD
# Add and commit your files separately to make multiple commits: e.g
git add app/
git commit -m "add all files in app directory"
git add config/
git commit -m "add all files in config directory"
在这里,你成功地将最后的承诺分成两项承诺。
我意识到我已经推着一个承诺与一个类型在其中。为了放弃,我做了以下事情:
git commit --amend -m "T-1000, advanced prototype"
git push --force
警告:强迫推你的变化将重新写下远方分支与你的当地一个. 确保你不会过度写下任何你想保持的东西. 也要小心强迫推一个修改(重新写)承诺,如果其他人与你分享分支,因为他们将需要重新写下自己的历史,如果他们有旧的副本的承诺,你刚刚重新写。
如果你只想修改你的最后一个承诺消息,那么做: git commit --amend
它会把你推到你的文本编辑器,让你改变最后的承诺消息。
如果您想更改前三個承諾訊息,或任何承諾訊息到這一點,請將 HEAD~3 傳送到 git rebase -i 命令: git rebase -i HEAD~3
如果这是你的最后承诺,只需修改承诺:
git commit --amend -o -m "New commit message"
如果这是一个埋葬的承诺,使用令人惊叹的互动折叠:
git rebase -i @~9 # Show the last 9 commits in a text editor
运行 vimtutor 如果你有时间 hjkl 匹配运动密钥 ← ↓ ↑→ 所有命令都可以用“范围”预定,例如 3j 移动下三个行 i 输入输入模式 - 文本你输入将显示在文件 Esc 或 Ctrlc 输出输入模式和返回“正常”模式 u 到 undo Ctrlr 重定向 dd, dw, dl 删除一个行,字,或字母, 相应 cc, cw, cl 更改一个行,字母,或字母, re
如果你编辑了很多文本,然后转到Dvorak键盘配置,学习触摸类型,并学习Vim。
此分類上一篇
ProTipTM: 不要害怕使用重写历史的“危险”命令进行实验* - Git 不会默认删除您的订单 90 天; 您可以在重写中找到它们:
$ git reset @~3 # Go back three commits
$ git reflog
c4f708b HEAD@{0}: reset: moving to @~3
2c52489 HEAD@{1}: commit: more changes
4a5246d HEAD@{2}: commit: make important changes
e8571e4 HEAD@{3}: commit: make some changes
... earlier commits ...
$ git reset 2c52489
... and you're back where you started