Git Push返回"一切都是最新的"

时间:2014-05-28 20:31:08

标签: git github

我试图将我更新的文件推送到github上的远程存储库,使用git版本1.8.4.2运行OSX Snow Leopard。

我已成功完成git init,然后是git add .git remote add origin https://github.com/me/repo.git。然后,我做了git commit -m "first commit",然后是git push origin master

所有这一切都很有效

问题是当我尝试提交并再次推送时,我收到了一条消息。我更新了一些文件,例如,使用消息进行提交,然后运行git push remote origin

该命令有效,除非它说"一切都是最新的"。我扫描了大约六个堆栈溢出问题,类似的错误,其中很多都与没有在正确的分支或处于分离头模式有关。我相信我的情况既不是。

以下是git log --graph --all --decorate --pretty=oneline的结果:

* 6926001f0eed54c05f807eb04ed05fd0584cd2e6 (HEAD, origin/master, master) first commit

这里是git remote show origin

* remote origin
  Fetch URL: https://github.com/me/repo.git
  Push  URL: https://github.com/me/repo.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local ref configured for 'git push':
    master pushes to master (up to date)

这里是git branch -v

* master 6926001 first commit

我不确定我能提供哪些其他信息,但请告诉我,我会更新问题。我是git的新手,感谢阅读!

编辑:

我再次运行第二次提交并收到此消息:

# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   file1
#   modified:   file2
#   modified:   file3
#
no changes added to commit (use "git add" and/or "git commit -a")

1 个答案:

答案 0 :(得分:5)

git commit实际进行新提交之前,您需要将文件添加到“临时区域”。 1

“暂存区”允许您按照所需的方式排列所有内容,这有时与工作目录中所需的设置不同(例如,您可能需要调整配置文件以测试新功能的第1部分) ,但不想提交特定的配置文件更改)。

git status之前运行git commit以查看准备提交的内容以及尚未上演的内容通常是明智之举。此外,git diff --cached显示将提交的内容(将HEAD提交与暂存区域进行比较),而git diff没有--cached则显示不会承诺,即尚未上演的。

作为快捷方式,您可以使用git commit -a自动添加modified输出中显示为deletedgit status的文件。 (但这不会添加“未跟踪”的文件。再次,请参阅git status的输出。)

为了完整性,我将添加git diff HEAD显示您运行git commit -a时将提交的内容。 (这三个git diff变体列在git diff documentation下的示例部分中。)

以下是一些关于暂存区域的Web引用:

http://gitready.com/beginner/2009/01/18/the-staging-area.html

http://git-scm.com/book/en/Getting-Started-Git-Basics(这是Pro Git的书,非常好,但也很混乱,主要是因为git本身可能会让人感到困惑)。

https://softwareengineering.stackexchange.com/questions/69178/what-is-the-benefit-of-gits-two-stage-commit-process-staging


1 技术上并不完全正确:更确切地说,就在提交之前,git commit会快速比较提交内容与当前HEAD提交。如果没有差异,除非您指定--allow-empty,否则它会停止。使用-a,“提交内容”包括已修改和已删除的文件;只有当没有时,你仍然需要--allow-empty来进行新的提交。

相关问题