emacs-devel
[Top][All Lists]
Advanced

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

Re: Git question: when using branches, how does git treat working files


From: Steinar Bang
Subject: Re: Git question: when using branches, how does git treat working files when changing branches?
Date: Wed, 28 Oct 2015 21:00:38 +0100
User-agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.4 (windows-nt)

>>>>> Alan Mackenzie <address@hidden>:

> So, what happens to to changes in the working directory when changing
> branches?
> 1. git refuses to change branches because there are uncommitted changes.

If the branch you change to wants to modify one of the files you have
local changes in, git will abort the branch change with the message:
 error: Your local changes to the following files would be overwritten by 
checkout:
        filename
 Please, commit your changes or stash them before you can switch branches.
 Aborting

> 2. git changes branches, discarding all uncommitted changes.

Not by default, but using "-f" or "--force" will allow you to change
branch while overwriting local changes.

> 3. git changes branches, leaving the changes from the previous branch in
> the working directory.

If the branch change doesn't overwrite any of the files where you have
local changes, this is what will happen.

> What I really want to happen is
> 4. git maintains uncommitted changes separately in each branch.

> I suspect 4. is not the way git works.

Correct.

> So, how do I best simulate 4.?

git stash
git checkout some-branch
git stash pop

> I would like to be able to move freely between git branches without
> suffering stupid restrictions like having to worry about preserving
> changes in the working directory.  Is there some variant of "git stash"
> which might do what I want?

You mean, automatically...?

Dunno.

I mostly just try changing the branch, and revert to
 git stash
 git checkout some-branch
 git stash pop
if git complains about local changes being overwritten.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]