我试图将我更新的文件推送到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")
答案 0 :(得分:5)
在git commit
实际进行新提交之前,您需要将文件添加到“临时区域”。 1
“暂存区”允许您按照所需的方式排列所有内容,这有时与工作目录中所需的设置不同(例如,您可能需要调整配置文件以测试新功能的第1部分) ,但不想提交特定的配置文件更改)。
在git status
之前运行git commit
以查看准备提交的内容以及尚未上演的内容通常是明智之举。此外,git diff --cached
显示将提交的内容(将HEAD
提交与暂存区域进行比较),而git diff
没有--cached
则显示不会承诺,即尚未上演的。
作为快捷方式,您可以使用git commit -a
自动添加modified
输出中显示为deleted
或git 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本身可能会让人感到困惑)。
1 技术上并不完全正确:更确切地说,就在提交之前,git commit
会快速比较提交内容与当前HEAD
提交。如果没有差异,除非您指定--allow-empty
,否则它会停止。使用-a
,“提交内容”包括已修改和已删除的文件;只有当没有时,你仍然需要--allow-empty
来进行新的提交。