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

Re: git -C has unexpected behaviour

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Nov 4, 2016, 16:36 UTC
Message-ID
<alpine.DEB.2.20.1611041719140.3108@virtualbox>
In-Reply-To
<CADJspfL3zVCPv+mfRM_v4ukUggQkhGH7KB50a+HLPZXZqn1pXw@mail.gmail.com>
Hi Felix,
On Fri, 4 Nov 2016, Felix Nairz wrote:
Show 13 quoted lines
> Now, to the unexpected part, which I think is a bug:
> 
> If the TestData folder is there, but empty (I deleted all the files),
> then running
> 
> git -C .\TestData reset --hard
> 
> will NOT throw me an error but run
> 
> git reset --hard
> 
> on the git repository (not the submodule in the sub-directory!),
> without warning, or error.

I *think* that this is actually intended. Please note that -C is *not* a synonym of --git-dir. It is more of a synonym of

	cd .\TestData
	git reset --hard

In other words, you probably expected -C to specify the top-level directory of a worktree, and you expected Git to error out when it is not. Instead, Git will treat -C as a directory *from where to start*; It *can* be a subdirectory of the top-level directory of the worktree.

Please note that
	git --git-dir=.\TestData\.git reset --hard

will not work, though, as it mistakes the current directory for the top-level directory of the worktree. What you want to do is probably

	git -C .\TestData --git-dir=.git reset --hard

This will tell Git to change the current working directory to the top-level of your intended worktree, *and* state that the repository needs to be in .git (which can be a file containing "gitdir: <real-git-dir>", which is the default in submodules).

If the repository is *not* found, this command will exit with a failure.

Ciao, Johannes

Previous: Stefan BellerNext: Felix Nairz
Message 3 of 5 in “git -C has unexpected behaviour”
  1. Felix NairzNov 4, 2016
  2. Stefan BellerNov 4, 2016
  3. Johannes SchindelinNov 4, 2016
  4. Felix NairzNov 7, 2016
  5. Johannes SchindelinNov 7, 2016

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.