git checkout --recurse-submodules deletes local modifications

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi there!

It seems git checkout --recurse-submodules doesn't live up to its
documentation. According to the docs:

> If local modifications in a submodule would be overwritten the checkout will fail unless -f is used.

Here's an MWE where git checkout --recurse-submodules does overwrite
local modifications:

```
# Prepare repo
rm -rf /tmp/test
mkdir /tmp/test
cd /tmp/test
git init
git submodule add git@xxxxxxxxxx:octocat/Hello-World.git
git commit -m "Add submodule"
git checkout -b other
cd Hello-World
git checkout 762941318ee16e59dabbacb1b4049eec22f0d303
cd ..
git add Hello-World
git commit -m "Change submodule commit"

# Add local modification
echo boo! > Hello-World/README

# Switch branches. This completes without error, and deletes the
change introduced in the previous line.
git checkout main --recurse-submodules
```

I believe part of the problem is that
762941318ee16e59dabbacb1b4049eec22f0d303 and
7fd1a60b01f91b314f59955a4e4d4e80d8edf11d (the Hello-World master
commit) are the same; the last line does report an error if I make
`other` point at 553c2077f0edc3d5dc5d17262f6aa498e69d6f8e instead of
the above commit. However, I don't think this changes the fact that
the above MWE makes git checkout --recurse-submodules look pretty
dangerous.

I'd love to hear if

1) the above is intended behavior,
2) I'm doing something wrong, or
3) this is a bug.

Best regards, and thanks for all your hard work,
Simon




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux