threads / discuss / 51040

Surprising semantics of "git add file"

Subject: Surprising semantics of "git add file"

## tl;dr

4 messages between May 5, 2019 and May 6, 2019.

replies: 3people: 2as markdown or json

Ulrich Windl· May 5, 2019, 20:02 UTC · lore
Hi!

Reading the manual, I realized that "it is the way it is (it works as documented)", but to me it's surprising, meaning: I feel it's wrong: (git-2.16.4) I have staged several files, and then I do "git add -interactive file" to add some selected changes from file. After that a "git diff --cached file" just shows the changes added interactively, but when I "git add file" to commit those changes), even the unstaged changes from file are committed. I feel this is inconsistent: At least "git diff --cached file" should behave like "git commit file", meaning "git commit file" should be fixed IMHO. Or are there any reasonable use cased for that?

Regards, Ulrich Windl

Ulrich Windl· May 5, 2019, 20:12 UTC · re: Ulrich Windl · lore

Antw: Surprising semantics of "git add file"

Actually things are worse: When I tried to fix the comment for the unexpected commit at least using "git commit --amend", more files were committed!
>>> Ulrich Windl 05.05.19 22.02 Uhr >>>
Hi!

Reading the manual, I realized that "it is the way it is (it works as documented)", but to me it's surprising, meaning: I feel it's wrong: (git-2.16.4) I have staged several files, and then I do "git add -interactive file" to add some selected changes from file. After that a "git diff --cached file" just shows the changes added interactively, but when I "git add file" to commit those changes), even the unstaged changes from file are committed. I feel this is inconsistent: At least "git diff --cached file" should behave like "git commit file", meaning "git commit file" should be fixed IMHO. Or are there any reasonable use cased for that?

Regards, Ulrich Windl

Andreas Schwab· May 5, 2019, 20:31 UTC · re: Ulrich Windl · lore

Re: Surprising semantics of "git add file"

On Mai 05 2019, "Ulrich Windl" <Ulrich.Windl@rz.uni-regensburg.de> wrote:
> After that a "git diff --cached file" just shows the changes added interactively, but when I "git add file" to commit those changes), even the unstaged changes from file are committed.
Did you really mean "git add" here?  It doesn't commit, it adds to the index.
Andreas.
-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
Ulrich Windl· May 6, 2019, 07:14 UTC · re: Andreas Schwab · lore

Antw: Re: Surprising semantics of "git add file"

>>> Andreas Schwab <schwab@linux-m68k.org> schrieb am 05.05.2019 um 22:31 in
Nachricht <87o94gbq46.fsf@igel.home>:
> On Mai 05 2019, "Ulrich Windl" <Ulrich.Windl@rz.uni‑regensburg.de> wrote:
> 
>> After that a "git diff ‑‑cached file" just shows the changes added 
> interactively, but when I "git add file" to commit those changes), even the
> unstaged changes from file are committed.
> 
> Did you really mean "git add" here?  It doesn't commit, it adds to the 
> index.

Sorry, you are right "git commit file" I meant. I guess I was distracted when writing that. Otherwise it wouldn't make any sense.

Show 7 quoted lines
> 
> Andreas.
> 
> ‑‑ 
> Andreas Schwab, schwab@linux‑m68k.org 
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
> "And now for something completely different."

← back to recent threads