我在承诺信中写错了。

我怎么能改變訊息呢?承諾尚未推動。


当前回答

您可以使用 git-rebase-reword

它旨在以同样的方式编辑任何承诺(不只是最后) - 修改

$ git rebase-reword <commit-or-refname>

它被命名为反对互动的行动,以改变一个承诺:“反对”。 查看此帖子和人 - 部分互动模式-

例子:

$ git rebase-reword b68f560
$ git rebase-reword HEAD^

其他回答

更改最新承诺消息

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 filter-branch 为此。

git filter-branch -f --msg-filter "sed 's/errror/error/'" $flawed_commit..HEAD

它不像一个虚假的吉特承诺 - 修正,但它特别有用,如果你已经有一些合并后你的错误的承诺消息。

请注意,这将试图重新写下头部和错误的承诺之间的每一个承诺,所以你应该非常明智地选择你的msg过滤器命令 ;-)

使用

git commit --amend

要详细理解,一个很好的帖子是 4. 重新写 Git 历史. 它也谈论什么时候不使用 git commit --amend。

如果您没有将代码推到您的远程分支(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 status git add --all git commit -am “消息走到这里关于变化” git pull <origin master> git push <origin master>