# How to execute a command on git am/rebase/cherry pick --abort ?

5 messages from 2024-01-18 to 2024-01-29. Participants: Konstantin Kharlamov, Patrick Steinhardt.
Thread: https://gitlist.dev/t/60759

## Konstantin Kharlamov, 2024-01-18 12:53

Subject: How to execute a command on git am/rebase/cherry pick --abort ?
Message-ID: <d66ef46827fc7391bd74ece943afa2c5245896d6.camel@yandex.ru>
URL: https://gitlist.dev/e/d66ef46827fc7391bd74ece943afa2c5245896d6.camel%40yandex.ru

```
(please keep me CC'ed, I'm not subscribed)

Hello!

There's a well-known problem of git not fully checking out changes
while doing e.g. `git checkout` and similar commands when you have
submodules. So e.g. if HEAD changes a submodule commit and you do an
interactive rebase to HEAD~2, you may be lucky to find a submodule
commit change in `git diff` (because if you don't get lucky, you won't
notice that and commit the change to the unrelated HEAD~2).

As a workaround I have a `git submodule update` inside `post-checkout`
hook.

Now, the problem is I still often finding myself having the wrong
submodule ID, and I tracked down that problem to commands such as
`am/rebase/cherry-pick --abort` also not updating the submodule, nor
executing `post-checkout`.

I looked through `man githooks` but couldn't find any way to execute a
`git submodule update` during these aborts.

Any ideas how to fix these?

```

## Patrick Steinhardt, 2024-01-18 13:29

Subject: Re: How to execute a command on git am/rebase/cherry pick --abort ?
Message-ID: <Zaknu0nwBucHVJPP@tanuki>
URL: https://gitlist.dev/e/Zaknu0nwBucHVJPP%40tanuki
In-Reply-To: <d66ef46827fc7391bd74ece943afa2c5245896d6.camel@yandex.ru>

```
On Thu, Jan 18, 2024 at 03:53:21PM +0300, Konstantin Kharlamov wrote:
> (please keep me CC'ed, I'm not subscribed)
> 
> Hello!
> 
> There's a well-known problem of git not fully checking out changes
> while doing e.g. `git checkout` and similar commands when you have
> submodules. So e.g. if HEAD changes a submodule commit and you do an
> interactive rebase to HEAD~2, you may be lucky to find a submodule
> commit change in `git diff` (because if you don't get lucky, you won't
> notice that and commit the change to the unrelated HEAD~2).
> 
> As a workaround I have a `git submodule update` inside `post-checkout`
> hook.
> 
> Now, the problem is I still often finding myself having the wrong
> submodule ID, and I tracked down that problem to commands such as
> `am/rebase/cherry-pick --abort` also not updating the submodule, nor
> executing `post-checkout`.
> 
> I looked through `man githooks` but couldn't find any way to execute a
> `git submodule update` during these aborts.
> 
> Any ideas how to fix these?

Are you aware of the `submodule.recurse` config? If set, it should cause
git-checkout(1) and many other commands to recurse into submodules and
update them accordingly. This should both make your post-checkout hook
obsolete and should also work with git-cherry-pick(1) et al.

Patrick

```

## Konstantin Kharlamov, 2024-01-18 13:30

Subject: Re: How to execute a command on git am/rebase/cherry pick --abort ?
Message-ID: <2c996cb7f83466a4ded11f4f581748c82d24b3c3.camel@yandex.ru>
URL: https://gitlist.dev/e/2c996cb7f83466a4ded11f4f581748c82d24b3c3.camel%40yandex.ru
In-Reply-To: <Zaknu0nwBucHVJPP@tanuki>

```
On Thu, 2024-01-18 at 14:29 +0100, Patrick Steinhardt wrote:
> On Thu, Jan 18, 2024 at 03:53:21PM +0300, Konstantin Kharlamov wrote:
> > (please keep me CC'ed, I'm not subscribed)
> > 
> > Hello!
> > 
> > There's a well-known problem of git not fully checking out changes
> > while doing e.g. `git checkout` and similar commands when you have
> > submodules. So e.g. if HEAD changes a submodule commit and you do
> > an
> > interactive rebase to HEAD~2, you may be lucky to find a submodule
> > commit change in `git diff` (because if you don't get lucky, you
> > won't
> > notice that and commit the change to the unrelated HEAD~2).
> > 
> > As a workaround I have a `git submodule update` inside `post-
> > checkout`
> > hook.
> > 
> > Now, the problem is I still often finding myself having the wrong
> > submodule ID, and I tracked down that problem to commands such as
> > `am/rebase/cherry-pick --abort` also not updating the submodule,
> > nor
> > executing `post-checkout`.
> > 
> > I looked through `man githooks` but couldn't find any way to
> > execute a
> > `git submodule update` during these aborts.
> > 
> > Any ideas how to fix these?
> 
> Are you aware of the `submodule.recurse` config? If set, it should
> cause
> git-checkout(1) and many other commands to recurse into submodules
> and
> update them accordingly. This should both make your post-checkout
> hook
> obsolete and should also work with git-cherry-pick(1) et al.
> 
> Patrick

Oh, this is amazing, thank you! No, I didn't know about it, will use!

```

## Konstantin Kharlamov, 2024-01-29 14:35

Subject: Re: How to execute a command on git am/rebase/cherry pick --abort ?
Message-ID: <4dd609ae2a33f3729291ff26b40632c8eb5decae.camel@yandex.ru>
URL: https://gitlist.dev/e/4dd609ae2a33f3729291ff26b40632c8eb5decae.camel%40yandex.ru
In-Reply-To: <Zaknu0nwBucHVJPP@tanuki>

```
On Thu, 2024-01-18 at 14:29 +0100, Patrick Steinhardt wrote:
> On Thu, Jan 18, 2024 at 03:53:21PM +0300, Konstantin Kharlamov wrote:
> > (please keep me CC'ed, I'm not subscribed)
> > 
> > Hello!
> > 
> > There's a well-known problem of git not fully checking out changes
> > while doing e.g. `git checkout` and similar commands when you have
> > submodules. So e.g. if HEAD changes a submodule commit and you do
> > an
> > interactive rebase to HEAD~2, you may be lucky to find a submodule
> > commit change in `git diff` (because if you don't get lucky, you
> > won't
> > notice that and commit the change to the unrelated HEAD~2).
> > 
> > As a workaround I have a `git submodule update` inside `post-
> > checkout`
> > hook.
> > 
> > Now, the problem is I still often finding myself having the wrong
> > submodule ID, and I tracked down that problem to commands such as
> > `am/rebase/cherry-pick --abort` also not updating the submodule,
> > nor
> > executing `post-checkout`.
> > 
> > I looked through `man githooks` but couldn't find any way to
> > execute a
> > `git submodule update` during these aborts.
> > 
> > Any ideas how to fix these?
> 
> Are you aware of the `submodule.recurse` config? If set, it should
> cause
> git-checkout(1) and many other commands to recurse into submodules
> and
> update them accordingly. This should both make your post-checkout
> hook
> obsolete and should also work with git-cherry-pick(1) et al.

It doesn't seem to work ☹ I've set it, and now supposed my top commit
changes submodule. So I do a `git rebase -i HEAD~2` and "reword" the
previous commit. After "reword"ing is done, git returns me back to HEAD
commit and when I execute `git diff` I see the submodule ID changed ☹

```

## Konstantin Kharlamov, 2024-01-29 14:40

Subject: Re: How to execute a command on git am/rebase/cherry pick --abort ?
Message-ID: <694c9c01947a7a2e67ea225b12112dcccdafbc9a.camel@yandex.ru>
URL: https://gitlist.dev/e/694c9c01947a7a2e67ea225b12112dcccdafbc9a.camel%40yandex.ru
In-Reply-To: <4dd609ae2a33f3729291ff26b40632c8eb5decae.camel@yandex.ru>

```
On Mon, 2024-01-29 at 17:35 +0300, Konstantin Kharlamov wrote:
> On Thu, 2024-01-18 at 14:29 +0100, Patrick Steinhardt wrote:
> > On Thu, Jan 18, 2024 at 03:53:21PM +0300, Konstantin Kharlamov
> > wrote:
> > > (please keep me CC'ed, I'm not subscribed)
> > > 
> > > Hello!
> > > 
> > > There's a well-known problem of git not fully checking out
> > > changes
> > > while doing e.g. `git checkout` and similar commands when you
> > > have
> > > submodules. So e.g. if HEAD changes a submodule commit and you do
> > > an
> > > interactive rebase to HEAD~2, you may be lucky to find a
> > > submodule
> > > commit change in `git diff` (because if you don't get lucky, you
> > > won't
> > > notice that and commit the change to the unrelated HEAD~2).
> > > 
> > > As a workaround I have a `git submodule update` inside `post-
> > > checkout`
> > > hook.
> > > 
> > > Now, the problem is I still often finding myself having the wrong
> > > submodule ID, and I tracked down that problem to commands such as
> > > `am/rebase/cherry-pick --abort` also not updating the submodule,
> > > nor
> > > executing `post-checkout`.
> > > 
> > > I looked through `man githooks` but couldn't find any way to
> > > execute a
> > > `git submodule update` during these aborts.
> > > 
> > > Any ideas how to fix these?
> > 
> > Are you aware of the `submodule.recurse` config? If set, it should
> > cause
> > git-checkout(1) and many other commands to recurse into submodules
> > and
> > update them accordingly. This should both make your post-checkout
> > hook
> > obsolete and should also work with git-cherry-pick(1) et al.
> 
> It doesn't seem to work ☹ I've set it, and now supposed my top commit
> changes submodule. So I do a `git rebase -i HEAD~2` and "reword" the
> previous commit. After "reword"ing is done, git returns me back to
> HEAD
> commit and when I execute `git diff` I see the submodule ID changed ☹

Well, FTR, I just figured out why that happens, but the option being
broken still stands.

So, turns out what happened is that I have `git submodule update` call
in my `post-checkout` hook, which that `submodule.recurse` option
doesn't account for. Unfortunately, if removing it fixes the situation
mentioned above, however git breaks elsewhere: if I know execute "edit"
on the previous commit and use `git diff`, I see the submodule ID in
the changes.

So… I guess my initial question still stands: is there any hook to fix
the problem of git not updating the submodule upon `git rebase --abort`
and co?

```
