threads / discuss / 58670

'git commit .' in a subdirectory also commits staged files in other subdirectories

Subject: 'git commit .' in a subdirectory also commits staged files in other subdirectories

## tl;dr

4 messages between Oct 21, 2022 and Nov 7, 2022.

replies: 3people: 3as markdown or json

Yuri· Oct 21, 2022, 19:40 UTC · lore

I had several staged files in various subdirectories of the cloned repository tree.

'git commit .' in one of them attempted to commit all of them, not only the files in that subdirectory.

This is a very unreasonable behavior, because while being in any subdirectory 'git commit .' should only affect that subdirectory, and not files elsewhere.

git-2.38.0
FreeBSD 13.1
Yuri
Taylor Blau· Oct 21, 2022, 21:48 UTC · re: Yuri · lore

Re: 'git commit .' in a subdirectory also commits staged files in other subdirectories

Hi Yuri,
On Fri, Oct 21, 2022 at 12:40:51PM -0700, Yuri wrote:
Show 9 quoted lines
> I had several staged files in various subdirectories of the cloned
> repository tree.
>
> 'git commit .' in one of them attempted to commit all of them, not
> only the files in that subdirectory.
>
> This is a very unreasonable behavior, because while being in any
> subdirectory 'git commit .' should only affect that subdirectory, and
> not files elsewhere.

That isn't right, though I can't reproduce what you describe from your report. Try this script out:

--- >8 --- #!/bin/sh

rm -fr repo git init repo cd repo

mkdir -p dir touch dir/c touch a touch b git add a b dir/c git commit -m "a"

date >>b date >>dir/c

(
  cd dir
  git commit . -m "dir"
)
--- 8< ---

`repo` ends up wtih the contents of dir/c committed, but b is still modified (and its latest changes not part of the most recent commit).

Can you share a reproduction script?

Thanks, Taylor

Junio C Hamano· Oct 21, 2022, 22:02 UTC · re: Taylor Blau · lore

Re: 'git commit .' in a subdirectory also commits staged files in other subdirectories

Taylor Blau <me@ttaylorr.com> writes:
Show 10 quoted lines
>> 'git commit .' in one of them attempted to commit all of them, not
>> only the files in that subdirectory.
>>
>> This is a very unreasonable behavior, because while being in any
>> subdirectory 'git commit .' should only affect that subdirectory, and
>> not files elsewhere.
>
> That isn't right, though I can't reproduce what you describe from your
> report. Try this script out:
> ...

"git commit --include ." would exhibit the behaviour, but that should not be the default, so I am also puzzled.

Yuri· Nov 7, 2022, 18:45 UTC · re: Taylor Blau · lore

Re: 'git commit .' in a subdirectory also commits staged files in other subdirectories

On 10/21/22 14:48, Taylor Blau wrote:
> That isn't right, though I can't reproduce what you describe from your
> report. Try this script out:

I don't know how to reproduce this on purpose. But I just got another instance of the problem.

I am in the FreeBSD ports Git repository, in the math/cimod subfolder. Another subfolder, audio/sonic-visualiser, also has changes.

Here is the command:

[yuri@yv /disk-samsung/freebsd-ports/math/cimod]$ git commit . hint: Waiting for your editor to close the file... # Uncomment and add a short description of why things changed. math/cimod: Update 1.4.43 -> 1.4.45

# Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # category/port: Subject goes here, max 50 cols -| # <then a blank line> #                                                         72 columns --| # # Do not add a Submitted by line.  If someone besides the committer sent in the # change, the commit author should be set using `git commit --author`. # # Uncomment and complete these metadata fields, as appropriate: # # PR:           <If and which Problem Report is related.> Reported by:    portscout # Reviewed by:  <If someone else reviewed your modification.> # Tested by:    <If someone else tested the change.> # Approved by:  <If you needed approval for this commit.> # Obtained from:        <If the change is from a third party.> # Fixes:        <Short hash and title line of commit fixed by this change> # MFH:          <Ports tree branch name you plan to merge to.> # Relnotes:     <Set to 'yes' for mention in release notes.> # Security:     <Vulnerability reference (one per line) or description.> # Sponsored by: <If the change was sponsored by an organization.> # Pull Request: <https://github.com/freebsd/freebsd-ports/pull/###> # Differential Revision: <https://reviews.freebsd.org/D###> # # "Pull Request" and "Differential Revision" require the *full* GitHub or # Phabricator URL. # # On branch main # Your branch is up to date with 'origin/main'. # # Changes to be committed: #       modified:   Makefile #       modified:   distinfo # # Changes not staged for commit: #       modified:   ../../audio/sonic-visualiser/Makefile #       modified:   ../../audio/sonic-visualiser/distinfo #       deleted: ../../audio/sonic-visualiser/files/patch-acinclude.m4 #       deleted: ../../audio/sonic-visualiser/files/patch-base.pro #       deleted: ../../audio/sonic-visualiser/files/patch-config.pri.in #       deleted: ../../audio/sonic-visualiser/files/patch-configure.ac #       deleted: ../../audio/sonic-visualiser/files/patch-convert.pro #       deleted: ../../audio/sonic-visualiser/files/patch-server.pro #       deleted: ../../audio/sonic-visualiser/files/patch-sonic-visualiser.pro

Git said that 2 files are to be committed, Makefile and distnfo. This is correct.

However, the resulting commit also has audio/sonic-visualiser:
  git diff 99f39b9798ff81b8fb529bea7c16d96e27aecfca~1 
99f39b9798ff81b8fb529bea7c16d96e27aecfca | grep diff
diff --git a/audio/sonic-visualiser/files/patch-acinclude.m4 
b/audio/sonic-visualiser/files/patch-acinclude.m4
diff --git a/audio/sonic-visualiser/files/patch-base.pro 
b/audio/sonic-visualiser/files/patch-base.pro
diff --git a/audio/sonic-visualiser/files/patch-config.pri.in 
b/audio/sonic-visualiser/files/patch-config.pri.in
diff --git a/audio/sonic-visualiser/files/patch-configure.ac 
b/audio/sonic-visualiser/files/patch-configure.ac
diff --git a/audio/sonic-visualiser/files/patch-convert.pro 
b/audio/sonic-visualiser/files/patch-convert.pro
diff --git a/audio/sonic-visualiser/files/patch-server.pro 
b/audio/sonic-visualiser/files/patch-server.pro
diff --git a/audio/sonic-visualiser/files/patch-sonic-visualiser.pro 
b/audio/sonic-visualiser/files/patch-sonic-visualiser.pro
- # (because of the difficulty of getting them running nicely in the
diff --git a/audio/sonic-visualiser/files/patch-sv.pro 
b/audio/sonic-visualiser/files/patch-sv.pro
diff --git a/audio/sonic-visualiser/files/patch-svapp_acinclude.m4 
b/audio/sonic-visualiser/files/patch-svapp_acinclude.m4
diff --git a/audio/sonic-visualiser/files/patch-svcore_acinclude.m4 
b/audio/sonic-visualiser/files/patch-svcore_acinclude.m4
diff --git a/audio/sonic-visualiser/files/patch-svcore_config.pri.in 
b/audio/sonic-visualiser/files/patch-svcore_config.pri.in
diff --git a/audio/sonic-visualiser/files/patch-svgui_acinclude.m4 
b/audio/sonic-visualiser/files/patch-svgui_acinclude.m4
diff --git 
a/audio/sonic-visualiser/files/patch-svgui_layer_WaveformLayer.cpp 
b/audio/sonic-visualiser/files/patch-svgui_layer_WaveformLayer.cpp
diff --git a/audio/sonic-visualiser/files/patch-svgui_view_Overview.cpp 
b/audio/sonic-visualiser/files/patch-svgui_view_Overview.cpp
diff --git a/math/cimod/Makefile b/math/cimod/Makefile
diff --git a/math/cimod/distinfo b/math/cimod/distinfo


This is WRONG!


There *is* a bug in Git.


Each commit needs to be individually checked to see if the right files 
were committed. The Git's commit description can't be trusted.

When it says "Changes not staged for commit" - these files should *not* 
be committed,

This has already hurt me several times.


This should be the highest priority bug.


Yuri

← back to recent threads