git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git commits unstaged files

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jan 18, 2019, 10:32 UTC
Message-ID
<nycvar.QRO.7.76.6.1901181129310.41@tvgsbejvaqbjf.bet>
In-Reply-To
<19f764a20b384e099372921d76ec4f73@thisisant.com>
Hi Beenish,
On Thu, 17 Jan 2019, Khurshid, Beenish wrote:
Show 20 quoted lines
> I frequently use 'git add -p' to filter changes before committing. This
> usually works, but on many occasions, the use of add and commit results
> in unstaged chunks and files being committed.
> 
> Steps to reproduce:
> 1. Create unstaged changes
> 2. Use add -p to add some of those changes
> 3. Use git commit to commit the staged changes
> 
> Expectation: Only added chunks are committed.
> 
> Result:
> 1. When editing the commit message, the added files appear staged in the comments at the end of the commit message, and the unstage files appear unstaged. (expected behaviour)
> 2. All unstaged changes and files are committed.
> 3. Once git enters this state, even git add produces the same result: Using git add to only add some files (and not chunks), and subsequently committing, results in unstaged files also being committed.
> 4. Even after restarting git bash, the behaviour persists.
> 5. The same behaviour occurs when adding and committing a file, while leaving other files unstaged, when using Git GUI instead of Git Bash 
> 
> Environment:
> Git version 2.12.2.windows.2
That's almost two years old. We're at v2.20.1.windows.1 now.
> Windows 10 enterprise
> Hooks: commit-msg, and pre-commit
> Changes were being committed, reset, and rebased prior to this add -p attempt
I cannot reproduce.

FWIW I sometimes have the same problem, but in all those cases the problem is my muscle memory that makes me add the `-a` option to `git commit` before I can stop myself.

> If more information is needed, please do not hesitate to contact me.
> Since this is a significant part of my workflow, the failure of the
> command to work in the expected way is fairly disruptive to my workflow.

You could investigate further by setting GIT_TRACE=1 to see whether any other Git command is run from your hooks.

In any case, if you desire help, the best way forward would be to generate a Minimal, Complete & Verifiable Example (MCVE, https://stackoverflow.com/help/mcve) that in particular does not require your particular setup such as hooks, specific Git version, etc.

Ciao, Johannes

Show 13 quoted lines
> 
> Any help or thoughts would be appreciated!
> 
> Kind Regards,
> Beenish Khurshid, E.I.T I Applications Engineer
> ANT Wireless | 124 - 30 Bow Street Common, Cochrane, AB, Canada T4C 2N1
> P: 587.493.4156 | F: 403.932.6521
> 
> 
>  
> 
> 
> 
Previous: Khurshid, BeenishNext: Khurshid, Beenish
Message 2 of 4 in “git commits unstaged files”
  1. Khurshid, BeenishJan 17, 2019
  2. Johannes SchindelinJan 18, 2019
  3. Khurshid, BeenishJan 18, 2019
  4. Johannes SchindelinJan 21, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.