错误 - 在Git上没有提交任何内容

时间:2012-11-01 02:23:19

标签: git

我正在尝试将我的first_app提交到Git上。我在命令行中输入以下内容(见下文),但我的输出显示没有任何内容可以提交。

new-host:first_app XXXXXX$ cd /Users/XXXXXX/rails_projects/first_app
new-host:first_app XXXXXX$ git init
Reinitialized existing Git repository in /Users/XXXXXX/rails_projects/first_app/.git/
new-host:first_app XXXXXX$ git add .
new-host:first_app XXXXXX$ git status
# On branch master
nothing to commit (working directory clean)
new-host:first_app XXXXXX$ 

在另一个终端我运行$ rails server来创建我的first_app。为什么没有提交?

我该如何解决这个问题?谢谢!

4 个答案:

答案 0 :(得分:7)

注意第一行输出:

  

重新初始化现有的Git存储库

您已在该目录中拥有git repo,并且没有未提交的更改。

答案 1 :(得分:2)

完成后

git add .

您需要提交您刚刚上演的更改:

git commit -m "my first commit"

您可以使用git show命令查看最新的提交。

答案 2 :(得分:1)

也许您以前在第一次创建git存储库时添加并提交了?

我能够通过以下方式重现:

durrantm.../aaa$ git init
Initialized empty Git repository in /home/durrantm/play/aaa/.git/
durrantm.../aaa$ l
total 16
drwxrwxr-x 14 durrantm 4096 Oct 31 22:28 ../
-rw-rw-r--  1 durrantm   11 Oct 31 22:29 ggg
drwxrwxr-x  3 durrantm 4096 Oct 31 22:29 ./
drwxrwxr-x  7 durrantm 4096 Oct 31 22:29 .git/
durrantm.../aaa$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       ggg
nothing added to commit but untracked files present (use "git add" to track)
durrantm.../aaa$ git add .
durrantm.../aaa$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#       new file:   ggg
#
durrantm.../aaa$ git commit
[master (root-commit) 953c83f] new
 1 file changed, 1 insertion(+)
 create mode 100644 ggg
durrantm.../aaa$ l
total 16
drwxrwxr-x 14 durrantm 4096 Oct 31 22:28 ../
-rw-rw-r--  1 durrantm   11 Oct 31 22:29 ggg
drwxrwxr-x  3 durrantm 4096 Oct 31 22:29 ./
drwxrwxr-x  8 durrantm 4096 Oct 31 22:29 .git/
durrantm.../aaa$ git init
Reinitialized existing Git repository in /home/durrantm/play/aaa/.git/
durrantm.../aaa$ l
total 16
drwxrwxr-x 14 durrantm 4096 Oct 31 22:28 ../
-rw-rw-r--  1 durrantm   11 Oct 31 22:29 ggg
drwxrwxr-x  3 durrantm 4096 Oct 31 22:29 ./
drwxrwxr-x  8 durrantm 4096 Oct 31 22:30 .git/
durrantm.../aaa$ git add .
durrantm.../aaa$ git status
# On branch master
nothing to commit (working directory clean)
durrantm.../aaa$ 
durrantm.../aaa$ git commit
# On branch master
nothing to commit (working directory clean)

注意{I} nothing to commit之后git add .的结尾durrantm.../aaa$ rm -rf .git/ durrantm.../aaa$ l total 12 drwxrwxr-x 14 durrantm 4096 Oct 31 22:28 ../ -rw-rw-r-- 1 durrantm 11 Oct 31 22:29 ggg drwxrwxr-x 2 durrantm 4096 Oct 31 22:34 ./ durrantm.../aaa$ git init Initialized empty Git repository in /home/durrantm/play/aaa/.git/ durrantm.../aaa$ l total 16 drwxrwxr-x 14 durrantm 4096 Oct 31 22:28 ../ -rw-rw-r-- 1 durrantm 11 Oct 31 22:29 ggg drwxrwxr-x 3 durrantm 4096 Oct 31 22:34 ./ drwxrwxr-x 7 durrantm 4096 Oct 31 22:34 .git/ durrantm.../aaa$ git add . durrantm.../aaa$ git commit [master (root-commit) 380863a] wewew 1 file changed, 1 insertion(+) create mode 100644 ggg

一个'修复'是删除git存储库并重新启动,当你这样做时,你可以正常提交final,例如:

{{1}}

答案 3 :(得分:0)

看起来你已经在该文件夹中有一个初始化的git repo。它可能已经提交了所有文件,当你“重新初始化”时,你真的只是重新启动git服务。也许。尝试更改其中一个文件,然后键入以下命令:

cd /Users/XXXXXX/rails_projects/first_app/
git add .
git commit -a -m "commit message"

那应该承诺。您可能必须将CD命令更改为指向firstapp / git /,但老实说我不记得了。祝你好运!

相关问题