26

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

a paid nerd
  • 30,702
  • 30
  • 134
  • 179
deepblue
  • 8,426
  • 13
  • 48
  • 60
  • What operating system are you using? Specifically, are you using Git on Windows, and if so, under which environment? – Greg Hewgill Nov 16 '09 at 23:15
  • Ubuntu server, git 1.5.6 – deepblue Nov 16 '09 at 23:18
  • 1
    The first thing I might suggest is to upgrade your Git version, the latest version is 1.6.5.3. I'm pretty sure that those particular messages you quoted have been improved since 1.5.x. – Greg Hewgill Nov 16 '09 at 23:25
  • ah sorry, the version I have is 1.6.3.3 – deepblue Nov 16 '09 at 23:29
  • Yeah, I recommend upgrading beyond ubuntu's repository version simply because later versions seem to make handling whitespace much simpler: I jus' added the PPA here: https://launchpad.net/~git-core/+archive/ppa and the upgraded. – Kzqai Nov 16 '09 at 23:29
  • the version i have I just downloaded from gits official download site so that should be fine. thanks though I appreciate it – deepblue Nov 16 '09 at 23:36
  • I have just tried upgrading git to version 1.7.5, but I'm still experiencing "nothing to commit". Dunno how to solve it. – neoneye May 05 '11 at 14:26

8 Answers8

29

Short answer:

git push -u origin master

Longer answer:

You're most likely trying to push commits to a branch that wasn't created yet - for example, on a newly created Github repository without the README file automatically created. By calling git push -u origin master, you specify both the remote that you need to push to (origin, which is usually the git default) and the branch (master, also default in typical cases). According to the git documentation:

-u, --set-upstream For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull(1) and other commands. For more information, see branch..merge in git-config(1).

This means that after a successful run of this command, from then on you'll be able to just use git push and git pull and it will default to origin master (with some exceptions).

Community
  • 1
  • 1
d33tah
  • 10,999
  • 13
  • 68
  • 158
6

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
  • 62,540
  • 32
  • 99
  • 117
  • 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 Nov 16 '09 at 23:20
  • 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 Nov 16 '09 at 23:30
  • weird. I do a 'git add .' every time. that should do the trick.hmmm. thanks for pointing that out though – deepblue Nov 16 '09 at 23:34
  • Does it work if you explicitly add the files you want? `git add foo bar baz`? – Will Robertson Nov 16 '09 at 23:47
  • 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 Nov 17 '09 at 00:24
2

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 calledfoo.txt. To fix this you need to manuallygit rm foo.txtbefore doinggit commit`

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

mlibby
  • 6,567
  • 1
  • 32
  • 41
  • 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 Nov 16 '09 at 23:24
  • 1
    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. – mlibby Nov 16 '09 at 23:26
  • And by "make any changes" I include changes to the files, renaming the files, deleting files, adding files... anything that could confuse git. – mlibby Nov 16 '09 at 23:30
1

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
  • 1,141
  • 1
  • 11
  • 21
0

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
  • 15,584
  • 8
  • 52
  • 59
  • 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 Nov 16 '09 at 23:18
0

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
  • 11,496
  • 2
  • 33
  • 35
0

Guys I had the same problem with Git.
I am running Cygwin on windows 8.

  1. check if you have the repository that you want to commit to.
  2. check the path

$ git remote -v # this is how you can see your path

$ git remote set-url origin git@github.com:username/repos.git # this is how you set new path remotely to push files to the right repository. $ git remote -v # to check if the right path was set.

  1. $ git add .

4.

 $ git push origin master

HOPE THIS HELPS

oshaiken
  • 2,593
  • 1
  • 15
  • 25
0

Here's what I needed:

git push -u origin main

Jesus is Lord
  • 14,971
  • 11
  • 66
  • 97