我试图将我更新的文件推送到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
Run Code Online (Sandbox Code Playgroud)
这是 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)
Run Code Online (Sandbox Code Playgroud)
这是 git branch -v
* master 6926001 first commit
Run Code Online (Sandbox Code Playgroud)
我不确定我能提供哪些其他信息,但请告诉我,我会更新问题.我对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")
Run Code Online (Sandbox Code Playgroud)
您需要在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文档中列出,在EXAMPLES部分下面.)
以下是有关暂存区域的一些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进行新的提交.