git 为什么我不能提交?(您的分支是最新的'origin/master',未添加任何更改提交)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29703134/
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-09 03:05:11  来源:igfitidea点击:

Why can I not commit? (Your branch is up-to-date with 'origin/master', no changes added to commit)

macosgitterminalgit-commit

提问by imasnake

I have been having some trouble committing a file to GitHub. I can make it to git add, but soon as I try $ git commit -m 'my message'I get an error, not allowing me to complete the process of adding a file.

我在向 GitHub 提交文件时遇到了一些问题。我可以使用 git add,但是我一尝试就$ git commit -m 'my message'收到错误,不允许我完成添加文件的过程。

$ git add HelloWorld.md

$ git commit -m 'Hello world'

I get the following answer (deleted: README.md& .DS_Storeare in red):

我得到以下答案(已删除:README.md&.DS_Store为红色):

On branch master

Your branch is up-to-date with 'origin/master'.

Changes not staged for commit:
        deleted:    README.md

Untracked files:
        .DS_Store

no changes added to commit

回答by Tom

If you changed the file but there is still nothing to commit, maybe you didn't add the file to git. (or replaced it after adding). Try adding the file before committing:

如果您更改了文件但仍然没有任何内容可以提交,则可能是您没有将文件添加到 git 中。(或添加后替换)。在提交之前尝试添加文件:

git add filename.ext

Or simply add the whole dir:

或者简单地添加整个目录:

git add .

回答by Oldskool

Apparently you did not change anything in the HelloWorld.md file (or it doesn't exist at all), so there is nothing to commit. If you just want to add an "empty" file, make sure to touch HelloWorld.mdfirst, so the file is actually created. If it does exist, edit it (using vim HelloWorld.mdfor example) and make sure to save the changes in your editor when you're done.

显然您没有更改 HelloWorld.md 文件中的任何内容(或者它根本不存在),因此无需提交任何内容。如果您只想添加一个“空”文件,请确保touch HelloWorld.md先添加,以便实际创建文件。如果确实存在,请对其进行编辑(vim HelloWorld.md例如使用)并确保在完成后将更改保存在编辑器中。

Once you've done that and there are actual changes to the file, you should be able to commit it.

完成此操作并且对文件进行了实际更改后,您应该能够提交它。

回答by jub0bs

You have nothing to commit. More specifically:

你没有什么可提交的。进一步来说:

  • README.mdwas a tracked file, but you deleted without using git rm README.md. Git detects that the file has been deleted, but you still have to stage that deletion if you want the latter to be effective in the next commit.
  • .DS_Storeis an untracked file; as such, it cannot be part of the next commit. (By the way, you should ignore such files globally.)
  • git add HelloWorld.mdhas no effect: the file is being tracked by Git, but there is nothing to stage in there, because you simply haven't made any changes to it since the last commit.

    How can I tell? If HelloWorld.mdwere a previously untracked file or if it were a tracked file which you changed since the last commit, git add HelloWorld.mdwould have successfully staged those changes; there would have been something to commit, and you would have been able to successfully commit.

  • README.md是一个跟踪文件,但您没有使用git rm README.md. Git 检测到该文件已被删除,但如果您希望后者在下一次提交中生效,您仍然必须暂存该删除操作。
  • .DS_Store是一个未跟踪的文件;因此,它不能成为下一次提交的一部分。(顺便说一句,您应该全局忽略此类文件。)
  • git add HelloWorld.md没有效果:该文件正在被 Git 跟踪,但没有任何内容可以暂存,因为自上次提交以来您根本没有对其进行任何更改。

    我怎么知道?如果HelloWorld.md是以前未跟踪的文件,或者是自上次提交后更改的跟踪文件,git add HelloWorld.md则将成功暂存这些更改;本来会有一些事情要提交,并且您将能够成功提交。

Make some changes, stage them, and then you'll be able to commit. Finally,

进行一些更改,暂存它们,然后您就可以提交了。最后,

Your branch is up-to-date with 'origin/master'

您的分支是最新的 'origin/master'

simply means

简单的意思

You haven't created any commits on mastersince you pushed to origin/master.

您还没有上创建的任何承诺master,因为你推到origin/master

Nothing to be alarmed about.

没什么好担心的。