I did a git commit -m "message"
like this:
> git commit -m "save arezzo files"
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: arezzo.txt
# modified: arezzo.jsp
#
no changes added to commit (use "git add" and/or "git commit -a")
But afterwards, when I do git status
it shows the same modified files:
> git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: arezzo.txt
# modified: arezzo.jsp
#
no changes added to commit (use "git add" and/or "git commit -a")
What am I doing wrong?
I copied a small sub project I had that was under Git source control into another project and forgot to delete the .git folder. When I went to commit I got the same message as above and couldn't clear it until I deleted the
.git
folder.It is a bit silly, but it is worth checking you don't have a .git folder under the folder that doesn't commit.
I find this problem appearing when I've done a
git add .
in a subdirectory below where my.gitignore
file lives (the home directory of my repository, so to speak). Try changing directories to your uppermost directory and runninggit add .
followed bygit commit -m "my commit message"
.You didn't add the changes. Either specifically add them via
or add all changes (from root path of the project)
or use the shorthand
-a
while commiting:if you have a subfolder, which was cloned from other git-Repository, first you have to remove the $.git$ file from the child-Repository:
rm -rf .git
after that you can change to parent folder and usegit add -A
.As the message says:
Git has a "staging area" where files need to be added before being committed, you can read an explanation of it here.
For your specific example, you can use:
(note the extra
a
in the flags, can also be written asgit commit -a -m "message"
- both do the same thing)Alternatively, if you want to be more selective about what you add to the commit, you use the git add command to add the appropriate files to the staging area, and git status to preview what is about to be added (remembering to pay attention to the wording used).
You can also find general documentation and tutorials for how to use git on the git documentation page which will give more detail about the concept of staging/adding files.
One other thing worth knowing about is interactive staging - this allows you to add parts of a file to the staging area, so if you've made three distinct code changes (for related but different functionality), you can use interactive mode to split the changes and add/commit each part in turn. Having smaller specific commits like this can be helpful.
Maybe an obvious thing, but...
If you have problem with the index, use git-gui. You get a very good view how the index (staging area) actually works.
Another source of information that helped me understand the index was Scott Chacons "Getting Git" page 259 and forward.
I started off using the command line because most documentation only showed that...
I think git-gui and gitk actually make me work faster, and I got rid of bad habits like "git pull" for example... Now I always fetch first... See what the new changes really are before I merge.