# [PATCH] Fix 'git commit -a' in a newly initialized repository

9 messages from 2007-02-22 to 2007-02-23. Participants: Fredrik Kuivinen, Johannes Schindelin, Nicolas Pitre, Junio C Hamano.
Thread: https://gitlist.dev/t/6916

## Fredrik Kuivinen, 2007-02-22 20:28

Subject: [PATCH] Fix 'git commit -a' in a newly initialized repository
Message-ID: <20070222202812.8882.44375.stgit@c165>
URL: https://gitlist.dev/e/20070222202812.8882.44375.stgit%40c165

```

With current git:

$ git init
$ git commit -a
cp: cannot stat `.git/index': No such file or directory

Output a nice error message instead.

Signed-off-by: Fredrik Kuivinen <frekui@gmail.com>

---

 git-commit.sh |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/git-commit.sh b/git-commit.sh
index ec506d9..476f4f1 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -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 &&

```

## Johannes Schindelin, 2007-02-22 20:42

Subject: Re: [PATCH] Fix 'git commit -a' in a newly initialized repository
Message-ID: <Pine.LNX.4.63.0702222140360.22628@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0702222140360.22628%40wbgn013.biozentrum.uni-wuerzburg.de
In-Reply-To: <20070222202812.8882.44375.stgit@c165>

```
Hi,

On Thu, 22 Feb 2007, Fredrik Kuivinen wrote:

> +		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

```

## Nicolas Pitre, 2007-02-22 20:54

Subject: Re: [PATCH] Fix 'git commit -a' in a newly initialized repository
Message-ID: <alpine.LRH.0.82.0702221550290.27932@xanadu.home>
URL: https://gitlist.dev/e/alpine.LRH.0.82.0702221550290.27932%40xanadu.home
In-Reply-To: <Pine.LNX.4.63.0702222140360.22628@wbgn013.biozentrum.uni-wuerzburg.de>

```
On Thu, 22 Feb 2007, Johannes Schindelin wrote:

> Hi,
> 
> On Thu, 22 Feb 2007, Fredrik Kuivinen wrote:
> 
> > +		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.

> 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

```

## Johannes Schindelin, 2007-02-22 20:59

Subject: Re: [PATCH] Fix 'git commit -a' in a newly initialized repository
Message-ID: <Pine.LNX.4.63.0702222157000.22628@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0702222157000.22628%40wbgn013.biozentrum.uni-wuerzburg.de
In-Reply-To: <alpine.LRH.0.82.0702221550290.27932@xanadu.home>

```
Hi,

On Thu, 22 Feb 2007, Nicolas Pitre wrote:

> On Thu, 22 Feb 2007, Johannes Schindelin wrote:
> 
> > On Thu, 22 Feb 2007, Fredrik Kuivinen wrote:
> > 
> > > +		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?

> > 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

```

## Nicolas Pitre, 2007-02-22 21:09

Subject: Re: [PATCH] Fix 'git commit -a' in a newly initialized repository
Message-ID: <alpine.LRH.0.82.0702221605080.27932@xanadu.home>
URL: https://gitlist.dev/e/alpine.LRH.0.82.0702221605080.27932%40xanadu.home
In-Reply-To: <Pine.LNX.4.63.0702222157000.22628@wbgn013.biozentrum.uni-wuerzburg.de>

```
On Thu, 22 Feb 2007, Johannes Schindelin wrote:

> Hi,
> 
> On Thu, 22 Feb 2007, Nicolas Pitre wrote:
> 
> > On Thu, 22 Feb 2007, Johannes Schindelin wrote:
> > 
> > > On Thu, 22 Feb 2007, Fredrik Kuivinen wrote:
> > > 
> > > > +		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?

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

```

## Johannes Schindelin, 2007-02-22 21:13

Subject: Re: [PATCH] Fix 'git commit -a' in a newly initialized repository
Message-ID: <Pine.LNX.4.63.0702222213120.22628@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0702222213120.22628%40wbgn013.biozentrum.uni-wuerzburg.de
In-Reply-To: <alpine.LRH.0.82.0702221605080.27932@xanadu.home>

```
Hi,

On Thu, 22 Feb 2007, Nicolas Pitre wrote:

> On Thu, 22 Feb 2007, Johannes Schindelin wrote:
> 
> > 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

```

## Junio C Hamano, 2007-02-22 21:36

Subject: Re: [PATCH] Fix 'git commit -a' in a newly initialized repository
Message-ID: <7vhctddge7.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vhctddge7.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <alpine.LRH.0.82.0702221605080.27932@xanadu.home>

```
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.

```

## Nicolas Pitre, 2007-02-23 00:06

Subject: Re: [PATCH] Fix 'git commit -a' in a newly initialized repository
Message-ID: <alpine.LRH.0.82.0702221904210.27932@xanadu.home>
URL: https://gitlist.dev/e/alpine.LRH.0.82.0702221904210.27932%40xanadu.home
In-Reply-To: <7vhctddge7.fsf@assigned-by-dhcp.cox.net>

```
On Thu, 22 Feb 2007, Junio C Hamano wrote:

> 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

```

## Junio C Hamano, 2007-02-23 05:03

Subject: Re: [PATCH] Fix 'git commit -a' in a newly initialized repository
Message-ID: <7vlkipbh4p.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vlkipbh4p.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <alpine.LRH.0.82.0702221904210.27932@xanadu.home>

```
Nicolas Pitre <nico@cam.org> writes:

> On Thu, 22 Feb 2007, Junio C Hamano wrote:
>
>> 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.

Yup.  Will apply Fredrik's original to 'maint'.

```
