我在承诺信中写错了。
我怎么能改變訊息呢?承諾尚未推動。
我在承诺信中写错了。
我怎么能改變訊息呢?承諾尚未推動。
当前回答
如果您需要在多个分支上更改一个旧的承诺消息(即与错误消息的承诺存在于多个分支),您可能需要使用:
git filter-branch -f --msg-filter \
'sed "s/<old message>/<new message>/g"' -- --all
Git 将创建一个临时目录,以重新编写,并在 refs/original/中备份旧参考。
-f 将执行操作,这是必要的,如果临时目录已经存在,或者如果已经有参考存储在 refs/original 下,如果不是这样,你可以放下这个旗帜. -- 将过滤分支选项与审查选项分开。
由于您的旧参考备份,您可以在执行命令之前轻松地返回状态。
说,你想恢复你的主人,并在分支 old_master 中访问它:
git checkout -b old_master refs/original/refs/heads/master
其他回答
如果您没有将代码推到您的远程分支(GitHub/Bitbucket),您可以按照下面的命令线更改承诺消息。
git commit --amend -m "Your new message"
如果你在一个特定的分支工作,这样做:
git commit --amend -m "BRANCH-NAME: new message"
如果你已经用错误的消息推了代码,你需要在更改消息时小心,也就是说,一旦你改变承诺消息并尝试再次推它,你会遇到问题。
请在做之前阅读我的全部答案。
git commit --amend -m "BRANCH-NAME : your new message"
git push -f origin BRANCH-NAME # Not a best practice. Read below why?
重要注意:当您直接使用强力压力时,您可能会遇到其他开发人员在同一分支上工作的代码问题,因此要避免这些冲突,您需要在强力压力之前从分支中提取代码:
git commit --amend -m "BRANCH-NAME : your new message"
git pull origin BRANCH-NAME
git push -f origin BRANCH-NAME
這是改變承諾訊息的最佳做法,如果它已經被推動。
更新您的最后一个错误的承诺消息与新的承诺消息在一个行:
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
git commit --amend -m "New commit message"
...任何人,这可能会使多线承诺消息或小纠正更有吸引力进入。
确保您在做此之前没有任何工作复制变更,或者它们也会被承诺(未进行的变更不会被承诺)。
git push <remote> <branch> --force
# Or
git push <remote> <branch> -f
// n is the number of commits up to the last commit you want to be able to edit
git rebase -i HEAD~n
一旦你错过了你的承诺,选择e/r来编辑消息:
如果你使用 git rebase -i HEAD~n 可以有更多的 n 命令. Git 将“收集”最后 n 命令中的所有命令,如果在这个范围之间有某个合并,你会看到所有的命令,所以结果将是 n + 。
好提示:
git-commit(1) 手动 页 git-rebase(1) 手动 页 git-push(1) 手动 页
如果你只是想编辑最新的承诺,使用:
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 rebase --interactive $parent_of_flawed_commit 如果你想修复几个错误的命令,通过最古老的命令的父母。 一个编辑会出现,从你给的所有命令的列表。 更改选择重新命令(或在旧版本的Git,编辑)在任何命令你想修复的前面。 一旦你保存,Git将重新播放列出的命令。
它是非常容易的;你不需要记住它 - 只是记住, git rebase - 互动允许你纠正命令,无论他们是多久以前。
请注意,你不会想改变你已经推的承诺,或者也许你会这样做,但在这种情况下,你将不得不非常小心地与任何可能推你的承诺并完成工作。