From: Junio C Hamano <gitster@pobox.com>
To: Nanako Shiraishi <nanako3@lavabit.com>
Cc: John Dlugosz <JDlugosz@TradeStation.com>,
git@vger.kernel.org, Paolo Bonzini <bonzini@gnu.org>,
Jay Soffian <jaysoffian@gmail.com>
Subject: Re: undoing something
Date: Tue, 17 Mar 2009 00:09:23 -0700 [thread overview]
Message-ID: <7vtz5ssk0s.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: 20090317064519.6117@nanako3.lavabit.com
Nanako Shiraishi <nanako3@lavabit.com> writes:
> Quoting John Dlugosz <JDlugosz@TradeStation.com>:
>
>> === Re: ===
>> (2) if you are not, you can obviously check out topic and do the above,
>> or "git branch -f topic topic^".
>> === end ===
>>
>> As documented, this destroys the existing branch and makes a new one.
>> That would, by design, blow away the reflog for that branch.
>
> Does it? If so I think you have an incorrect documentation.
>
> $ rm -fr /tmp/gomi && mkdir /tmp/gomi
> $ cd /tmp/gomi
> $ git init
> $ echo hello >world
> $ git add world
> $ git commit -m initial
> $ seq 1 100 | while read num; do echo $num >world; git commit -a -m $num; done
> $ git checkout -b side master~60
> $ git branch -f master master@{20}
> $ git log --oneline -g master | head -n 10
> 0acf8c1 master@{0}: branch: Reset from master@{20}
> 945c3ee master@{1}: commit: 100
> 54fcb36 master@{2}: commit: 99
> b314a1e master@{3}: commit: 98
> e91d999 master@{4}: commit: 97
> 0d88853 master@{5}: commit: 96
> 0124315 master@{6}: commit: 95
> 5df2cc5 master@{7}: commit: 94
> ...
> 0813a46 master@{9}: commit: 92
I didn't even notice there was another question buried. Thanks.
Documentation/git-branch.txt says this:
-f::
Force the creation of a new branch even if it means deleting
a branch that already exists with the same name.
which does imply that it first destroys the branch altogether and
recreates as if there was no such branch.
But that is actually not what the code does to reflog, and I think the
behaviour makes a lot more sense than "destroy and create" the
documentation implies. branch.c::create_branch() has this:
if (forcing)
snprintf(msg, sizeof msg, "branch: Reset from %s",
start_name);
else
snprintf(msg, sizeof msg, "branch: Created from %s",
start_name);
The message for your master@{0} example came from the "forcing" codepath.
The documentation is indeed wrong. It is more like "create a new branch,
or if the named branch already exists, reset the tip of it". If we want
to sound alarmist, we could add "even if it means making the existing
history unreachable from the new tip of the branch", but I think "reset"
already means that and it would be redundant.
The create_branch() function does another thing, though. It sets up the
tracking information _if asked_. Because one branch cannot track more
than one "other things" at once, it inevitably overwrites the previous
tracking information if you say "branch --track -f dev origin/dev" if dev
were tracking something else. But if you do not let it set up tracking,
the old tracking configuration is _not_ discarded. I am not sure if that
was intended (the branch.<name>.remote nor branch.<name>.merge variables
are not something I use myself), but it makes sort of sense. If you do
"git branch -f dev dev~2" to rewind its tip, you do not want to lose its
tracking information, so the current behaviour makes sense in that
respect.
I am not sure about how branch.autsetupmerge does interact with this in
the current code, nor how it should interact with it in the ideal world,
though. That's for interested parties (I suspect Jay and Paolo?) to
figure out.
next prev parent reply other threads:[~2009-03-17 7:11 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-16 19:06 undoing something John Dlugosz
2009-03-16 19:14 ` Junio C Hamano
2009-03-16 19:48 ` John Dlugosz
2009-03-16 20:11 ` Junio C Hamano
2009-03-16 20:51 ` Effective Posting John Dlugosz
2009-03-16 21:29 ` René Scharfe
2009-03-16 21:38 ` John Dlugosz
2009-03-16 22:21 ` Jay Soffian
2009-03-16 22:36 ` John Dlugosz
2009-03-16 21:45 ` (unknown), Nanako Shiraishi
2009-03-17 7:09 ` Junio C Hamano [this message]
2009-03-17 14:06 ` [PATCH] git-branch.txt: document -f correctly Michael J Gruber
2009-03-17 16:37 ` Junio C Hamano
2009-03-17 16:46 ` Michael J Gruber
2009-03-17 15:08 ` undoing something John Dlugosz
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: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vtz5ssk0s.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=JDlugosz@TradeStation.com \
--cc=bonzini@gnu.org \
--cc=git@vger.kernel.org \
--cc=jaysoffian@gmail.com \
--cc=nanako3@lavabit.com \
/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://80x24.org/mirrors/git.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).