2012-11-01 145 views
0

我正在嘗試將我的first_app提交到Git上。我在命令行輸入以下內容(見下文),但是我的輸出說沒有什麼可提交的。錯誤 - 沒有提交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。爲什麼沒有提交?

我該如何解決這個問題?謝謝!

回答

7

注意輸出的第一行:

重新初始化現有的Git倉庫

您已經在該目錄混帳回購協議,它具有未提交的更改。

+0

我刪除了初步承諾,當我意識到庫我承諾我的主目錄中的所有內容。我也做了一個'git reset --hard'來消滅之前的提交。鑑於它所說的「重新初始化......」,我描述的行動是否沒有任何效果? – LearningHowToCode

2

git add . 

後,您需要提交你剛剛上演了變化:

git commit -m "my first commit" 

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

+1

+1給git show – Pramesh

0

它看起來像你已經在該文件夾中初始化的git回購。它可能已經提交了所有文件,並且當您「重新初始化」時,您確實只是重新啓動了git服務。也許。嘗試更改其中一個文件,然後鍵入以下命令:

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

應該提交。您可能需要將CD命令更改爲指向firstapp/git /,但我實在不記得。祝你好運!

+0

謝謝你的建議。我仍然是一樣的信息。 – LearningHowToCode

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) 

注意如何git add .後有nothing to commit在最後,你所看到的。

一個「修復」是刪除的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 
+0

感謝您的注意!我試圖用'$ rm -rf.git /'和'$ l'刪除存儲庫。當我在命令行輸入'$ l'時,我得到了'-bash:l:command not found'。仍然卡住。還有其他建議嗎? – LearningHowToCode