From: David Kastrup <dak@gnu.org>
To: Alan Mackenzie <acm@muc.de>
Cc: emacs-devel@gnu.org
Subject: Re: Git question: when using branches, how does git treat working files when changing branches?
Date: Wed, 28 Oct 2015 20:44:57 +0100 [thread overview]
Message-ID: <87vb9q6ame.fsf@fencepost.gnu.org> (raw)
In-Reply-To: <20151028192017.GC2538@acm.fritz.box> (Alan Mackenzie's message of "Wed, 28 Oct 2015 19:20:17 +0000")
Alan Mackenzie <acm@muc.de> writes:
> Hello, Emacs.
>
> I want to start using git branches, so as to be able to work on several
> distinct things at the same time.
>
> My question is, how does git handle working files (which haven't been
> committed) when changing from one branch to another. I've spent the
> usual two hours searching the fine manuals without turning up a clear
> explanation.
>
> One thing that worries me is that the same command "git checkout" is
> used to change branches and to revert changes to a file. So it seems
> plausible that each time I swap to a different branch I'm in danger of
> irrevocably losing existing changes to source files.
>
> So, what happens to to changes in the working directory when changing
> branches?
> 1. git refuses to change branches because there are uncommitted changes.
> 2. git changes branches, discarding all uncommitted changes.
> 3. git changes branches, leaving the changes from the previous branch in
> the working directory.
Either 1 or 3, depending on whether the difference between the two
branches overlaps with the uncommitted changes or not. When Git can
just keep the uncommitted changes without conflict, it does that. This
comes in rather handy when you start doing some work, then figure out
that you really should have started a new branch. You can then just
checkout/create the new branch and ultimately commit there.
> What I really want to happen is
> 4. git maintains uncommitted changes separately in each branch.
Nope. There is only one index and one work directory. Just commit
them. You can also do "git stash" for saving index/work directory on a
stack and use "git stash pop" for getting them back out again later when
you switch back to your branch, but stashes are not tied to a particular
branch either.
It's usually just easier to do
git commit -m "wip" -a
and have a commit with message "wip" (work in progress) on the branch
where it belongs. You can fix that commit up later with
git commit --amend
in order to both fix the commit message as well as adding more changes
to it.
--
David Kastrup
next prev parent reply other threads:[~2015-10-28 19:44 UTC|newest]
Thread overview: 90+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-28 19:20 Git question: when using branches, how does git treat working files when changing branches? Alan Mackenzie
2015-10-28 19:44 ` David Kastrup [this message]
2015-10-28 20:00 ` Steinar Bang
2015-10-28 20:04 ` Ricardo Wurmus
2015-10-28 20:10 ` Alex Bennée
2015-10-28 22:32 ` Alan Mackenzie
2015-10-28 22:56 ` Xue Fuqiao
2015-10-28 22:59 ` Óscar Fuentes
2015-10-28 23:53 ` Alan Mackenzie
2015-10-29 0:17 ` Dmitry Gutov
2015-10-29 0:28 ` Michael Heerdegen
2015-10-29 0:49 ` Michael Heerdegen
2015-10-29 2:25 ` Yuri Khan
2015-10-29 8:21 ` David Kastrup
2015-10-29 12:35 ` Alan Mackenzie
2015-10-29 13:21 ` David Kastrup
2015-10-29 17:02 ` On the popularity of git [Was: Git question: when using branches, how does git treat working files when changing branches?] Alan Mackenzie
2015-10-29 17:22 ` David Kastrup
2015-10-29 18:08 ` John Wiegley
2015-10-30 7:48 ` Paul Eggert
2015-10-30 9:27 ` Alan Mackenzie
2015-10-30 9:48 ` David Kastrup
2015-10-30 10:34 ` Eli Zaretskii
2015-10-30 21:44 ` Paul Eggert
2015-10-30 9:09 ` joakim
2015-10-30 10:49 ` Yuri Khan
2015-10-31 3:16 ` Stephen J. Turnbull
2015-10-31 8:24 ` Eli Zaretskii
2015-10-31 8:32 ` Andreas Schwab
2015-10-31 11:35 ` Oleh Krehel
2015-10-31 12:19 ` David Kastrup
2015-11-02 22:01 ` Nikolaus Rath
2015-11-03 8:42 ` David Kastrup
2015-11-03 17:38 ` Nikolaus Rath
2015-10-31 16:02 ` On the popularity of git Stephen J. Turnbull
2015-11-01 8:08 ` Uwe Brauer
2015-10-31 16:50 ` Alan Mackenzie
2015-10-31 16:58 ` Dmitry Gutov
2015-11-02 22:05 ` Nikolaus Rath
2015-11-03 8:39 ` David Kastrup
2015-10-31 19:24 ` Stephen J. Turnbull
2015-10-31 20:13 ` David Kastrup
2015-10-31 21:08 ` Steinar Bang
2015-10-31 21:15 ` David Kastrup
2015-10-31 21:48 ` Alan Mackenzie
2015-11-01 8:17 ` Steinar Bang
2015-11-01 8:54 ` David Kastrup
2015-11-01 10:17 ` Steinar Bang
2015-11-01 11:15 ` Juanma Barranquero
2015-11-02 20:11 ` John Wiegley
2015-11-03 7:00 ` Oleh Krehel
2015-11-03 10:07 ` Dmitry Gutov
2015-11-03 11:58 ` Juanma Barranquero
2015-11-03 13:08 ` John Wiegley
2015-11-03 13:30 ` Juanma Barranquero
2015-11-03 13:38 ` Dmitry Gutov
2015-11-03 13:43 ` Juanma Barranquero
2015-11-03 13:49 ` Dmitry Gutov
2015-11-03 13:58 ` Juanma Barranquero
2015-11-03 14:14 ` Alan Mackenzie
2015-11-03 14:25 ` Juanma Barranquero
2015-11-03 13:43 ` Oleh Krehel
2015-11-03 14:35 ` Óscar Fuentes
2015-11-03 14:52 ` Juanma Barranquero
2015-11-03 15:58 ` Eli Zaretskii
2015-11-03 16:04 ` Dmitry Gutov
2015-11-03 18:14 ` Óscar Fuentes
2015-11-03 19:40 ` Jay Belanger
2015-11-03 20:15 ` John Wiegley
2015-11-03 20:24 ` Drew Adams
2015-11-03 20:35 ` Changing the tone of emacs-devel (Was: On the popularity of git) John Wiegley
2015-11-03 22:05 ` Artur Malabarba
2015-11-04 7:54 ` Nicolas Petton
2015-11-03 21:47 ` Changing the subject (was: " David Kastrup
2015-11-03 23:37 ` Marcin Borkowski
2015-11-04 0:27 ` John Yates
2015-11-04 1:40 ` Changing the subject Yann Hodique
2015-11-04 15:37 ` John Wiegley
2015-11-03 22:11 ` emacs-devel etiquette (was: Re: On the popularity of git) Stephen Leake
2015-11-04 11:12 ` Future emacs mailing lists. [Was: On the popularity of git] Alan Mackenzie
2015-11-04 7:52 ` On the popularity of git Stephen J. Turnbull
2015-11-03 20:53 ` Richard Stallman
2015-11-03 13:49 ` Andreas Schwab
2015-10-30 12:50 ` On the popularity of git [Was: Git question: when using branches, how does git treat working files when changing branches?] Juanma Barranquero
2015-10-30 14:15 ` David Kastrup
2015-10-30 16:54 ` Juanma Barranquero
2015-10-30 17:31 ` David Kastrup
2015-10-29 16:31 ` Git question: when using branches, how does git treat working files when changing branches? Eli Zaretskii
2015-10-29 16:16 ` Eli Zaretskii
2015-10-29 17:45 ` Davis Herring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87vb9q6ame.fsf@fencepost.gnu.org \
--to=dak@gnu.org \
--cc=acm@muc.de \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).