tags:

views:

217

answers:

5

I just commited my working tree, added to index first, with "$git commit -m 'test'" I saved the stdout-put from this to a file and I see at the top of it that it says

# 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)"

the problem is that my working tree is not being commited to the repo, and I have a feeling this has something to do with it

thanks

+2  A: 

Before you commit a change, you must add it to the index first:

git add myfile
git commit -m "test"

Alternatively, you can work in a more SVN-like style and commit everything that is changed:

git commit -a -m "test"

Or you can just add-and-commit a single file:

git commit myfile -m "test"
Will Robertson
did all of those. as I mentioned bellow in a comment to Jed's answer, I moved a lot of files around so I dont think commit -a would work in this case since files are being deleted and reintroduced... and I would think that git treats them as new files then
deepblue
I can only suggest that you didn't add the files to the repository when you thought you did; your message is exactly what I see when I run `git commit` without `git add` first.
Will Robertson
weird. I do a 'git add .' every time. that should do the trick.hmmm. thanks for pointing that out though
deepblue
Does it work if you explicitly add the files you want? `git add foo bar baz`?
Will Robertson
its a big change, as I said I reorganized the folder structure on the whole project so its way too many file movements/deletions to be done manually
deepblue
A: 

You really have to read the documentation.

git add yourfile
git commit -m "test"

Or, to commit all changed files --

git commit -a -m "test"
Jed Smith
ofcourse I added the working tree to the index first ($git add .), after which I ran ($git commit -m 'test' > view_file). I reorganized my working tree quite a bit from the last commit so lots of deleted files old places and reinsertion of those into new places... thats why Im saving output to a file so that I can review what git said
deepblue
+1  A: 

Did you do a git add . before you committed?

It's always wise to do a git status before either git add or git commit to see what's changed and staged, as well.

It's also very handy to do git diff to see the specific changes you are about to commit.

Here's what git status shows if you have added a file and then renamed it.

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

At this point you can just do git add . and then git status will give you more information, perhaps pointing out that you still have a new file and a deleted file called foo.txt. To fix this you need to manually git rm foo.txt before doing git commit`

In the future if you have files in a git repo that you want to move you should use git mv.

mcl
yeah 'git status' is cool. it too is reporting the message I put in the question. those damn changes are just not being committed. I spent all day reading tutorials and docs trying to find something to try out.
deepblue
You need to redo `git add` if you make any changes you want included in the commit. If you do a `git status` then `git add .` and then `git status` again, you should see a difference.
mcl
And by "make any changes" I include changes to the files, renaming the files, deleting files, adding files... anything that could confuse git.
mcl
+1  A: 

One other thing to note, git add adds the content of those files to the index at the time when you run it. If you run git add and then change the files, the new changes will not show up in the index.

Aaron
no additional work was done between 'add' and 'commit' invocations
deepblue
A: 

If you move files around and use git add afterwards, git only adds the new copy, but doesn't remove the old one:

$ 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")

To remove the old copies you should also use git rm:

$ git rm from
rm 'from'
$ git commit -m "..."
$ git status
# On branch master
nothing to commit (working directory clean)

But I don't see why it doesn't allow you to commit those changes.

Tomas Markauskas