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

add -u stages submodule changes when ignore=all is set

From
CECrockett, Eric <ericcro@amazon.com>
Date
May 29, 2020, 21:33 UTC
Message-ID
<f60c88d8ec2e4efcbbf4f78fd8f87da6@EX13D20UWA002.ant.amazon.com>
My expectation is that `git add -u` will stage precisely the changes listed in `git status` under "Changes not staged for commit". However, this isn't the case, and it's confusing. In particular, if I set `ignore=all` in .gitmodules for a submodule and then make changes to that submodule, `git status` does not show the changes (which is what I expect), but `git add -u` still stages the changes to the submodule (not what I expect)! This behavior occurs with git 2.26.2 on Ubuntu 18.04.
This script demonstrates the problem:
#!/bin/bash -ex

echo "Check out a random repository" git clone https://github.com/crockeea/cryptonite.git cd cryptonite

echo "Add a random submodule" git submodule add https://github.com/crockeea/wai.git

echo "Track an older commit in the submodule" cd wai git checkout HEAD^ cd .. git add -A git commit -m "Added submodule one commit behind its tip-of-master"

echo "What happens if I check out a newer commit in the submodule?" cd wai git checkout master cd .. git status echo "git status shows that the submodule is dirty"

echo "We can fix that by adding `ignore=all` to .gitmodules" echo -e '\tignore = all' >> .gitmodules

git status echo "Now the dirty submodule is not shown"

echo "This looks good; let's stage the changes to .gitmodules" git add -u

echo "And verify what was staged..." git status echo "The dirty submodule was staged! This is not what I expect." echo "I expect that `git add -u` will only stage the changes to .gitmodules"

cd .. rm -rf cryptonite

Regards, Eric Crockett

Message 1 of 1 in “add -u stages submodule changes when ignore=all is set”
  1. Crockett, EricMay 29, 2020

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.