git提交问题
我刚刚提交了我的工作树,首先添加到索引中,并使用“$git commit-m‘test’”,我将标准输出保存到一个文件中,在它的顶部显示git提交问题,git,Git,我刚刚提交了我的工作树,首先添加到索引中,并使用“$git commit-m‘test’”,我将标准输出保存到一个文件中,在它的顶部显示 # On branch master # Changed but not updated: # (use "git add/rm ..." to update what will be commited) # (use "git checkout -- ..." to discard changes in working directory)"
# On branch master
# Changed but not updated:
# (use "git add/rm ..." to update what will be commited)
# (use "git checkout -- ..." to discard changes in working directory)"
问题是,我的工作树没有被提交回购协议,我觉得这与此有关
谢谢在提交更改之前,必须先将其添加到索引中:
git add myfile
git commit -m "test"
或者,您可以以更类似SVN的方式工作,并提交所有更改的内容:
git commit -a -m "test"
或者,您可以只添加并提交一个文件:
git commit myfile -m "test"
你真的需要阅读文档
git add yourfile
git commit -m "test"
或者,提交所有更改的文件--
您在提交之前是否执行了git add. 明智的做法是在
git add
或git commit
之前执行git status
,查看发生了哪些更改和转移
执行git diff
查看即将提交的具体更改也非常方便
下面是git status
显示的内容,如果您添加了一个文件,然后将其重命名
me@home:~$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: foo.txt
#
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: foo.txt
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# bar.txt
me@home:~$git状态
#论分行行长
#要提交的更改:
#(使用“git重置磁头…”取消分级)
#
#新文件:foo.txt
#
#已更改但未更新:
#(使用“git add/rm…”更新将提交的内容)
#(使用“git签出--…”放弃工作目录中的更改)
#
#已删除:foo.txt
#
#未跟踪的文件:
#(使用“git add…”包含在将提交的内容中)
#
#bar.txt
此时,您只需执行git add.
,然后git status将为您提供更多信息,可能会指出您仍然有一个新文件和一个名为foo.txt的已删除文件。要解决此问题,您需要在执行git提交之前手动
git rm foo.txt`
将来,如果您想移动git repo中的文件,您应该使用git mv
另一件要注意的事情,git add会在运行索引时将这些文件的内容添加到索引中。如果运行git add然后更改文件,新的更改将不会显示在索引中。如果移动文件并在之后使用git add
,git只会添加新副本,而不会删除旧副本:
$ git status
# On branch master
nothing to commit (working directory clean)
$ mv from to
$ git add .
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: to
#
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: from
#
$ git commit -m "..."
$ git status
# On branch master
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: from
#
no changes added to commit (use "git add" and/or "git commit -a")
但我不明白为什么它不允许您提交这些更改。简短回答:
git-push-u原始主机
详细回答:
您很可能试图将提交推送到尚未创建的分支,例如,在新创建的Github存储库上,没有自动创建自述文件。通过调用git push-u origin master
,您可以指定需要推送到的远程设备(origin,通常是git默认值)和分支(master,在典型情况下也是默认值)。根据git文档:
-u,-设置为上游
对于每个最新或成功推送的分支,添加上游(跟踪)引用,由无参数git pull(1)和
其他命令。更多
有关详细信息,请参阅git配置中的branch..merge(1)
这意味着,在成功运行此命令后,从那时起,您将能够只使用git push
和git pull
,它将默认为origin master
(有一些)。伙计们,我对git也有同样的问题。
我正在Windows8上运行Cygwin
检查是否有要提交的存储库
检查路径
$git remote-v
#这是您查看路径的方式
$git远程设置url源git@github.com:username/repos.git
#这是远程设置新路径以将文件推送到正确存储库的方式。
$git remote-v
#检查是否设置了正确的路径
$git add
四,
希望这对您有所帮助您使用的是什么操作系统?具体来说,您是否在Windows上使用Git?如果是,在哪种环境下使用?Ubuntu服务器,Git 1.5.6我建议您首先升级Git版本,最新版本是1.6.5.3。我很确定你引用的那些特别的信息在1.5.x版之后已经改进了。啊,对不起,我的版本是1.6.3.3是的,我建议升级到ubuntu的存储库版本之外,因为更高的版本似乎会使处理空白变得更简单:我在这里添加了PPA:并且升级了。当然,我首先在索引中添加了工作树($git add.),然后运行($git commit-m'test'>view_file)。我重新组织了我的工作树,从上一次提交,所以很多删除的文件旧的地方和重新插入到新的地方。。。这就是为什么我要将输出保存到一个文件中,这样我就可以查看git所说的所有内容。正如我在对Jed回答的评论中提到的bellow,我移动了很多文件,所以我认为commit-a在这种情况下不起作用,因为文件正在被删除并重新引入。。。我认为git会将它们视为新文件,因此我只能建议您没有将文件添加到存储库中,而您认为您这样做了;您的消息正是我在运行git commit
而不运行git add
first.com时看到的消息。我每次都会做一个“git add”。那应该可以了。感谢您指出这一点,如果您显式添加所需的文件,它是否有效git add foo bar baz
?这是一个很大的变化,正如我说的,我在整个项目中重新组织了文件夹结构,因此需要手动执行太多的文件移动/删除。在“添加”和“提交”调用之间没有做任何额外的工作。它也在报道我在问题中提出的信息。那些该死的改变根本就没有实现。我花了一整天的时间阅读教程和文档,试图找到一些可以尝试的东西。如果您要在提交中包含任何更改,则需要重做git add
。如果执行git状态
,则执行git添加。
$ git status
# On branch master
nothing to commit (working directory clean)
$ mv from to
$ git add .
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: to
#
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: from
#
$ git commit -m "..."
$ git status
# On branch master
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: from
#
no changes added to commit (use "git add" and/or "git commit -a")
$ git rm from
rm 'from'
$ git commit -m "..."
$ git status
# On branch master
nothing to commit (working directory clean)
$ git push origin master