# Git automatic stashing?

7 messages from 2010-11-09 to 2010-11-09. Participants: Casey McGinty, Matthieu Moy, Martin von Zweigbergk, Nguyen Thai Ngoc Duy, Thomas Rast.
Thread: https://gitlist.dev/t/25684

## Casey McGinty, 2010-11-09 05:37

Subject: Git automatic stashing?
Message-ID: <AANLkTinwftXiZxbs_=PeM-MxQmMF4VaBCPEufH=OG6iU@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTinwftXiZxbs_%3DPeM-MxQmMF4VaBCPEufH%3DOG6iU%40mail.gmail.com
In-Reply-To: <AANLkTim3MacQK6EtTPNJsYbqb=5bOM3W3BXC6p=hT+PU@mail.gmail.com>

```
Is there any feature in git to perform and auto stash apply/pop when
trying to do a merge/rebase in a dirty working dir? This would save
some keystrokes from time-to-time, and make it easier for new users
unfamiliar with git.

Regards,
Casey McGinty

```

## Matthieu Moy, 2010-11-09 07:49

Subject: Re: Git automatic stashing?
Message-ID: <vpqlj53j5rv.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpqlj53j5rv.fsf%40bauges.imag.fr
In-Reply-To: <AANLkTinwftXiZxbs_=PeM-MxQmMF4VaBCPEufH=OG6iU@mail.gmail.com>

```
Casey McGinty <casey.mcginty@gmail.com> writes:

> Is there any feature in git to perform and auto stash apply/pop when
> trying to do a merge/rebase in a dirty working dir? This would save
> some keystrokes from time-to-time, and make it easier for new users
> unfamiliar with git.

I agree with the keystrokes part, but not with the fact that it would
make it easier in general. In the sequence

git stash
git merge
git stash pop

conflicts can occur in 2 distinct places. One can easily forsee this
senario occuring:

git stash
git merge
# fix conflicts
# git commit
# forget to do the action needed to get the "git stash pop"

and voila, you've just lost data.

Actually, what I'd like to see would be this feature, but limited to
the case where the merge is a fast-forward, because then, only the
last action of the sequence could possibly leave conflict, so Git
could finish with a message like "please fix conflicts and continue
working". Actually, this is not far from what "git checout -m" is
doing.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

```

## Martin von Zweigbergk, 2010-11-09 12:02

Subject: Re: Git automatic stashing?
Message-ID: <AANLkTi=L7WUPP_9ZmUmNKqYvQzpZFau4F0nWNxdLy1sZ@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTi%3DL7WUPP_9ZmUmNKqYvQzpZFau4F0nWNxdLy1sZ%40mail.gmail.com
In-Reply-To: <vpqlj53j5rv.fsf@bauges.imag.fr>

```
On Tue, Nov 9, 2010 at 2:49 AM, Matthieu Moy
<Matthieu.Moy@grenoble-inp.fr> wrote:
> Casey McGinty <casey.mcginty@gmail.com> writes:
>
>> Is there any feature in git to perform and auto stash apply/pop when
>> trying to do a merge/rebase in a dirty working dir? This would save
>> some keystrokes from time-to-time, and make it easier for new users
>> unfamiliar with git.
>
> I agree with the keystrokes part, but not with the fact that it would
> make it easier in general. In the sequence
>
> git stash
> git merge
> git stash pop
>
> conflicts can occur in 2 distinct places. [...]

Correct me if I'm wrong, but I think git will only stop you from
performing a merge if it would involve touching any of your dirty files,
so in the case of merge, I agree with Matthieu that temporarily stashing
your changes would probably just increase the risk of confusing the
user.

However, in the case of rebase, git will not let you rebase if *any*
file is dirty. So, in this case of rebase, there are often cases where
git prevents a rebase that could have been a stash + rebase + stash pop
without any conflicts in the pop step.

I know that the fact that 'git rebase' (usually in the form of a
'git pull' configured for rebase on the current branch) forces the user
to temporarily stash his changes has been somewhat annoying to some of
my colleagues.

I actually implemented support for stashing changes using 'stash create'
and 'stash apply', but only for non-interactive rebase. The implentation
supports a '--stash' argument and a 'rebase.stash' configuration. I am
currently working on refactoring git-rebase.sh and
git-rebase--interactive.sh, but once that's done, I will post an updated
version of the 'git rebase --stash' patch(es).

I later found out that this seems to have been attempted at least twice
before. The first time by Junio in 6c9ad16 (rebase: allow starting from
a dirty tree., 2007-07-09). This was later reverted. I think it was
reverted because the stashing was not optional.

Some months later, Simon Sasburg sent some patches on the same subject,
see http://thread.gmane.org/gmane.comp.version-control.git/63007/. These
patches don't see to have been accepted, but I'm not sure why.

```

## Nguyen Thai Ngoc Duy, 2010-11-09 12:36

Subject: Re: Git automatic stashing?
Message-ID: <AANLkTi=G=Xo90QayvuRDp=GTWtkES2fU0kkmn87Q09_2@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTi%3DG%3DXo90QayvuRDp%3DGTWtkES2fU0kkmn87Q09_2%40mail.gmail.com
In-Reply-To: <AANLkTinwftXiZxbs_=PeM-MxQmMF4VaBCPEufH=OG6iU@mail.gmail.com>

```
On Tue, Nov 9, 2010 at 12:37 PM, Casey McGinty <casey.mcginty@gmail.com> wrote:
> Is there any feature in git to perform and auto stash apply/pop when
> trying to do a merge/rebase in a dirty working dir? This would save
> some keystrokes from time-to-time, and make it easier for new users
> unfamiliar with git.

And when switching branches too.
-- 
Duy

```

## Martin von Zweigbergk, 2010-11-09 12:58

Subject: Re: Git automatic stashing?
Message-ID: <AANLkTin-qFrTnu+ZUx45Gbk_3m3843T1+n+aj3agwfzD@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTin-qFrTnu%2BZUx45Gbk_3m3843T1%2Bn%2Baj3agwfzD%40mail.gmail.com
In-Reply-To: <AANLkTi=G=Xo90QayvuRDp=GTWtkES2fU0kkmn87Q09_2@mail.gmail.com>

```
On Tue, Nov 9, 2010 at 7:36 AM, Nguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:
> On Tue, Nov 9, 2010 at 12:37 PM, Casey McGinty <casey.mcginty@gmail.com> wrote:
>> Is there any feature in git to perform and auto stash apply/pop when
>> trying to do a merge/rebase in a dirty working dir? This would save
>> some keystrokes from time-to-time, and make it easier for new users
>> unfamiliar with git.
>
> And when switching branches too.

When switching branches (or checking out a different commit in general),
I think git allows you to check out as long as the files that need to be
replaced have not been updated, much like when merging. As far as I can
see, that makes the benefit of temporarily stashing changes much smaller
(but not non-existent) in these two cases (checkout and merge) than it
is when rebasing.

Thinking a bit more about it, I think you are right, though, that it
would still be a nice-to-have, as an option. Currently, 'git rebase' is
more restrictive than 'git merge', but adding the option to 'git rebase'
would not just make it on par with 'git merge', but would actually make
it less restrictive than 'git merge', as even non-conflicting changes
within files would be automatically handled.

```

## Matthieu Moy, 2010-11-09 19:12

Subject: Re: Git automatic stashing?
Message-ID: <vpqd3qe8g5j.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpqd3qe8g5j.fsf%40bauges.imag.fr
In-Reply-To: <AANLkTi=G=Xo90QayvuRDp=GTWtkES2fU0kkmn87Q09_2@mail.gmail.com>

```
Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:

> On Tue, Nov 9, 2010 at 12:37 PM, Casey McGinty <casey.mcginty@gmail.com> wrote:
>> Is there any feature in git to perform and auto stash apply/pop when
>> trying to do a merge/rebase in a dirty working dir? This would save
>> some keystrokes from time-to-time, and make it easier for new users
>> unfamiliar with git.
>
> And when switching branches too.

Isn't that what "git checkout -m" does?

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

```

## Thomas Rast, 2010-11-09 19:19

Subject: Re: Git automatic stashing?
Message-ID: <201011092019.09239.trast@student.ethz.ch>
URL: https://gitlist.dev/e/201011092019.09239.trast%40student.ethz.ch
In-Reply-To: <vpqd3qe8g5j.fsf@bauges.imag.fr>

```
Matthieu Moy wrote:
> Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:
> 
> > On Tue, Nov 9, 2010 at 12:37 PM, Casey McGinty <casey.mcginty@gmail.com> wrote:
> >> Is there any feature in git to perform and auto stash apply/pop when
> >> trying to do a merge/rebase in a dirty working dir? This would save
> >> some keystrokes from time-to-time, and make it easier for new users
> >> unfamiliar with git.
> >
> > And when switching branches too.
> 
> Isn't that what "git checkout -m" does?

The problem with checkout -m is that you get only a single shot at
conflict resolution.  'git stash pop' does not drop the stash in the
case of a conflict, so you can try again.

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

```
