From: Junio C Hamano <gitster@pobox.com>
To: Christoph Bartoschek <ponto@pontohonk.de>
Cc: git@vger.kernel.org
Subject: Re: Prevent switching branches when local modifications exist
Date: Wed, 13 Jun 2012 16:35:46 -0700 [thread overview]
Message-ID: <7vfw9yg4z1.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <h5ina9-g9n.ln1@homer.bruehl.pontohonk.de> (Christoph Bartoschek's message of "Thu, 14 Jun 2012 00:52:01 +0200")
Christoph Bartoschek <ponto@pontohonk.de> writes:
> Hi,
>
> how can I prevent that git allows me to switch branches when there are
> uncommited local modifications?
>
> [14.1 (steiner_topo)]$ git checkout -b ergo
> Switched to a new branch 'ergo'
> [14.1 (ergo)]$ echo blub >> src/invtree.C
> [14.1 (ergo)]$ git checkout steiner_topo
> M src/invtree.C
> Switched to branch 'steiner_topo'
> [14.1 (steiner_topo)]$
>
> How can the last checkout be prevented?
The question sounds similar to asking "How can I prevent 'rm -r'
from removing anything when I type it in my home directory." It is
useful for 'rm -r' to remove everything recursively, but sometimes
you would want to prevent you from running it by mistake in a wrong
place. In general, there is no good direct solution for that.
A few usual ways people deal with this kind of issue are (1) to make
it easier to notice that they are "in a wrong place" (e.g. by having
the current directory in their prompt to avoid 'rm -r' in $HOME) and
training themselves to be careful, (2) to make it possible to
recover if that happens by mistake (e.g. by having .snapshot on the
filer).
For "checkout", an approach that corresponds to (1) is to have
branches and status in the prompt (available from git-completion).
Fortunately for (2) there isn't anything special necessary, as
checking out a different branch with "git checkout" does not lose
information, after creating and checking out the steiner_topo
branch, you can use checkout again to come back to ergo branch.
next prev parent reply other threads:[~2012-06-13 23:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-13 22:52 Prevent switching branches when local modifications exist Christoph Bartoschek
2012-06-13 23:35 ` Junio C Hamano [this message]
2012-06-14 7:17 ` Christoph Bartoschek
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vfw9yg4z1.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=ponto@pontohonk.de \
/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.
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 NNTP newsgroup(s).