LearningHowToCode
LearningHowToCode

Reputation: 125

Error - Nothing to commit on Git

I am trying to commit my first_app onto Git. I typed the following into the command lines (see below), but my output says that there is nothing to commit.

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$ 

In a different terminal I had ran $ rails server to create my first_app. Why is there nothing to commit?

How can I fix this? Thanks!

Upvotes: 1

Views: 11762

Answers (4)

Michael Durrant
Michael Durrant

Reputation: 96484

Perhaps you previously added and committed when creating the git repository the first time?

I was able to reproduce this with:

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)

Notice how there is nothing to commit at the end after a git add . as you are seeing.

One 'fix' is to remove the git repository and start again, when you do this you get to commit the final as normal, e.g.:

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

Upvotes: 1

Gazzini
Gazzini

Reputation: 738

It looks like you already had an initialized git repo in that folder. It might already have all the files committed, and when you "reinitialize" you're really just restarting the git service. Maybe. Try changing one of the files, then type the following commands:

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

That should commit. You might have to change the CD command to point to firstapp/git/, but I honestly don't remember. Good luck!

Upvotes: 0

Greg Hewgill
Greg Hewgill

Reputation: 993085

After doing

git add .

you need to commit the changes you just staged:

git commit -m "my first commit"

You can view the latest commit using the git show command.

Upvotes: 2

SLaks
SLaks

Reputation: 887453

Notice the first line of output:

Reinitialized existing Git repository

You already have a git repo in that directory, and it has no uncommitted changes.

Upvotes: 7

Related Questions