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

Bug report: git reset --hard does not fix submodule worktree

From
BLBilly O'Neal (VC LIBS) <bion@microsoft.com>
Date
Nov 4, 2017, 00:46 UTC
Message-ID
<BN6PR21MB0114B8ECD6E8A158FB4A6FBFCB520@BN6PR21MB0114.namprd21.prod.outlook.com>
Hello, Git folks. I managed to accidentally break the our test lab by attempting to git mv a directory with a submodule inside. It seems like if a reset does an undo on a mv, the workfold entry should be fixed to put the submodule in its old location. Consider the following sequence of commands:

Setup a git repo with a submodule: mkdir metaproject mkdir upstream cd metaproject git init cd ..\upstream git init echo hello > test.txt git add -A git commit -m "an example commit" cd ..\metapoject mkdir start git submodule add ../upstream start/upstream git add -A git commit -m "Add submodule in start/upstream."

Move the directory containing the submodule: git mv start target git add -A git commit -m "Moved submodule parent directory."

Check that the worktree got correctly fixed by git mv; this output is as expected:
type .git\modules\start\upstream\config
[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
        worktree = ../../../../target/upstream
[remote "origin"]
        url = C:/Users/bion/Desktop/upstream
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
Now try to go back to the previous commit using git reset --hard:
git log --oneline
 1f560be (HEAD -> master) Moved submodule parent directory.
 a5977ce Add submodule in start/upstream.
git reset --hard a5977ce
 warning: unable to rmdir target/upstream: Directory not empty
 HEAD is now at a5977ce Add submodule in start/upstream.
Check that the worktree got fixed correctly; it did not:
type .git\modules\start\upstream\config
[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
        worktree = ../../../../target/upstream
[remote "origin"]
        url = C:/Users/bion/Desktop/upstream
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
Is git reset intended to put the submodule in the right place? If not, is there a command we can run before/after reset to restore consistency?
Thanks folks!
Billy O'Neal
Next: Stefan Beller
Message 1 of 2 in “Bug report: git reset --hard does not fix submodule worktree”
  1. Billy O'Neal (VC LIBS)Nov 4, 2017
  2. Stefan BellerNov 6, 2017

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.