1

我正在尝试将我的 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

4 回答 4

7

注意输出的第一行:

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

您已经在该目录中有一个 git 存储库,并且它没有未提交的更改。

于 2012-11-01T02:24:46.250 回答
2

做完之后

git add .

您需要提交刚刚暂存的更改:

git commit -m "my first commit"

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

于 2012-11-01T02:30:58.820 回答
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)

请注意您所看到nothing to commit的 a 之后的结尾如何。git add .

一个“修复”是删除 git 存储库并重新开始,当您这样做时,您可以正常提交最终版本,例如:

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
于 2012-11-01T02:31:43.630 回答
0

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

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

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

于 2012-11-01T02:31:08.130 回答