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

Re: git -C has unexpected behaviour

From
FNFelix Nairz <felix.nairz@gmail.com>
Date
Nov 7, 2016, 07:26 UTC
Message-ID
<CADJspf+zqj2hHjD85dvt8Y4HKPViubvTzybbTq5mJDGCh2q1UQ@mail.gmail.com>
In-Reply-To
<alpine.DEB.2.20.1611041719140.3108@virtualbox>
Hi guys,
thanks for the answer and the clarification.

From what you are saying I can see that this expects as designed. It's confusing in the submodule case, but I get you don't want to add extra rules which slow down performance and mess with other people at the same time.

I will look into the git-dir solution, this seems to be exactly what I need.
Thanks, Felix

On Fri, Nov 4, 2016 at 5:36 PM, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:

Show 47 quoted lines
> Hi Felix,
>
> On Fri, 4 Nov 2016, Felix Nairz wrote:
>
>> 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: Johannes SchindelinNext: Johannes Schindelin
Message 4 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.