Fix 'git commit -a' in a newly initialized repository
PATCH 1/1 Fix 'git commit -a' in a newly initialized repository
With current git:
$ git init $ git commit -a cp: cannot stat `.git/index': No such file or directory
Output a nice error message instead.
---
git-commit.sh | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
git-commit.sh +4 -0
@@ -318,6 +318,10 @@ esac case "$all,$also" in t,) + if test ! -f "$THIS_INDEX" + then + die 'nothing to commit (use "git add file1 file2" to include for commit)' + fi save_index && ( cd_to_toplevel &&
Hi,
git-commit.sh esac · line 323
Quoted 1 line · Fredrik Kuivinen
git-commit.sh +1
-0+ die 'nothing to commit (use "git add file1 file2" to include for commit)'
Would it not make more sense to tell the user about "git add ."? Maybe together with a hint about .gitignore?
This error message is important. The most likely recipients are total git newsters, and we really should try to help them here.
Ciao,
Dscho
Quoted 7 lines · Johannes Schindelin
Hi,
git-commit.sh esac · line 323
Quoted 1 line · Fredrik Kuivinen
git-commit.sh +1
-0+ die 'nothing to commit (use "git add file1 file2" to include for commit)'Would it not make more sense to tell the user about "git add ."?
Isn't what the patch does? IMHO it looks just like the empty commit message which is good.
Quoted 5 lines
Maybe
together with a hint about .gitignore?This error message is important. The most likely recipients are total git newsters, and we really should try to help them here.
Sure. But to really help newsters it is better _not_ to talk about .gitignore at all. It certainly won't exist at that point anyway.
Nicolas
Hi,
Quoted 10 lines · Nicolas Pitre
Quoted 5 lines · Johannes Schindelin
git-commit.sh esac · line 323
Quoted 1 line · Fredrik Kuivinen
git-commit.sh +1
-0+ die 'nothing to commit (use "git add file1 file2" to include for commit)'Would it not make more sense to tell the user about "git add ."?
Isn't what the patch does? IMHO it looks just like the empty commit message which is good.
I wanted to get at the "." thing. You know, when I start a project with git, there are usually some files there already. Provided I have a .gitignore there, I can just say "git add ." and be done.
But maybe that is _not_ common practice?
Quoted 7 lines
Quoted 4 lines
Maybe together with a hint about .gitignore?
This error message is important. The most likely recipients are total git newsters, and we really should try to help them here.
Sure. But to really help newsters it is better _not_ to talk about .gitignore at all. It certainly won't exist at that point anyway.
Hmm. That is a really good point. Hmmm. I think you're right.
Ciao,
Dscho
Quoted 12 lines · Johannes Schindelin
Hi,
Quoted 8 lines · Nicolas Pitre
Quoted 5 lines · Johannes Schindelin
git-commit.sh esac · line 323
Quoted 1 line · Fredrik Kuivinen
git-commit.sh +1
-0+ die 'nothing to commit (use "git add file1 file2" to include for commit)'Would it not make more sense to tell the user about "git add ."?
Quoted 8 lines
Quoted 2 lines
Isn't what the patch does? IMHO it looks just like the empty commit message which is good.
I wanted to get at the "." thing. You know, when I start a project with git, there are usually some files there already. Provided I have a .gitignore there, I can just say "git add ." and be done.
But maybe that is _not_ common practice?
Well... If you're that acquainted with GIT to perform the above, I'm sure a message like "use "git add file1 file2" to include for commit" won't leave you puzzled. ;-)
Nicolas
If we want to limit the help to lone liner, I am with Nicolas and Fredrik on this one. Suggesting only "git add ." does not feel helpful.
However, because ! test -f "$THIS_INDEX" is such a special case (totally new check-in), we can afford to be verbose if we wanted to, and offer tons of possibilities, say:
die 'nothing to commit. You can use "git add file..."
to include individual files, or use "git add ." if you want to include all files in the current directory, for your first commit.'
But if we want to say "for your first commit" in the message, we should also be checking if HEAD commit really does not exist.
Quoted 11 lines · Junio C Hamano
However, because ! test -f "$THIS_INDEX" is such a special case (totally new check-in), we can afford to be verbose if we wanted to, and offer tons of possibilities, say:
die 'nothing to commit. You can use "git add file..."
to include individual files, or use "git add ." if you want to include all files in the current directory, for your first commit.'But if we want to say "for your first commit" in the message, we should also be checking if HEAD commit really does not exist.
Seems to me that the single line message avoids all those issues.
Nicolas
Quoted 11 lines · Nicolas Pitre
Quoted 9 lines · Junio C Hamano
However, because ! test -f "$THIS_INDEX" is such a special case (totally new check-in), we can afford to be verbose if we wanted to, and offer tons of possibilities, say:
die 'nothing to commit. You can use "git add file..."
to include individual files, or use "git add ." if you want to include all files in the current directory, for your first commit.'
Quoted 4 lines
Quoted 2 lines
But if we want to say "for your first commit" in the message, we should also be checking if HEAD commit really does not exist.
Seems to me that the single line message avoids all those issues.
Yup. Will apply Fredrik's original to 'maint'.
Hi,
Quoted 11 lines · Nicolas Pitre
Quoted 5 lines · Johannes Schindelin
I wanted to get at the "." thing. You know, when I start a project with git, there are usually some files there already. Provided I have a .gitignore there, I can just say "git add ." and be done.
But maybe that is _not_ common practice?
Well... If you're that acquainted with GIT to perform the above, I'm sure a message like "use "git add file1 file2" to include for commit" won't leave you puzzled. ;-)
;-) Yes, you are right!
Ciao,
Dscho