git 将空提交推送到远程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20138640/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 17:21:14  来源:igfitidea点击:

Pushing empty commits to remote

gitgit-commit

提问by mrutyunjay

I have pushed one commit to remote but now I realized that the commit message is not correct. I would like to change the commit message but AFAIK it is not possible. So i decided to create empty commit with correct message:

我已将一个提交推送到远程,但现在我意识到提交消息不正确。我想更改提交消息,但 AFAIK 这是不可能的。所以我决定用正确的消息创建空提交:

git commit --allow-empty

Are there any disadvantages/consequences of pushing empty commits? Is there any problem I might face in future because of this empty commit??

推送空提交有什么缺点/后果吗?由于这个空提交,我将来可能会遇到什么问题吗?

回答by Gabriele Petronella

You won't face any terrible consequence, just the history will look kind of confusing.

你不会面临任何可怕的后果,只是历史看起来有点混乱。

You couldchange the commit message by doing

可以通过执行更改提交消息

git commit --amend
git push --force-with-lease # (as opposed to --force, it doesn't overwrite others' work)

BUTthis will override the remote history with yours, meaning that if anybody pulled that repo in the meanwhile, this person is going to be very mad at you...

但是这将覆盖与您的远程历史记录,这意味着如果有人同时撤消该回购,此人将对您非常生气......

Just do it if you are the only person accessing the repo.

如果您是唯一访问 repo 的人,请执行此操作。

回答by xor

pushing commits, whether empty or not, causes eventual git hooks to be triggered. This can do either nothing or have world shattering consequences.

推送提交,无论是否为空,都会导致最终的 git 钩子被触发。这可能什么也不做,也可能会产生惊天动地的后果。

回答by yamafontes

Is there any disadvantages/consequences of pushing empty commits?

推送空提交有什么缺点/后果吗?

Aside from the extreme confusion someone might get as to why there's a bunch of commits with no content in them on master, not really.

除了极度困惑之外,有人可能会问为什么在 master 上有一堆没有内容的提交,而不是真的。

You canchange the commit that you pushed to remote, but the sha1 of the commit (basically it's id number) will change permanently, which alters the source tree -- You'd then have to do a git push -fback to remote.

可以更改推送到远程的提交,但提交的 sha1(基本上是 id 号)将永久更改,这会改变源树——然后您必须git push -f返回到远程。

回答by 153957

As long as you clearly reference the other commit from the empty commit it should be fine. Something like:

只要您清楚地从空提交中引用了另一个提交,就应该没问题。就像是:

Commit message errata for [commit sha1]

[new commit message]

As others have pointed out, this is often preferable to force pushing a corrected commit.

正如其他人指出的那样,这通常比强制推送更正的提交更可取。

回答by sarjit07

 $ git commit --allow-empty -m "Trigger Build"

回答by David Okwii

What about this;

那这个呢;

 git commit --allow-empty-message -m ''