Re: [PATCH] Proof-of-concept patch to remember what the detached HEAD was
- From
Björn Steinbrink <b.steinbrink@gmx.de>
- Date
- Oct 15, 2009, 14:11 UTC
- Message-ID
- <20091015141151.GA7867@atjola.homenet>
- In-Reply-To
- <m3bpk8g6nj.fsf@localhost.localdomain>
On 2009.10.15 05:54:52 -0700, Jakub Narebski wrote:
Show 22 quoted lines
> James Pickens <jepicken@gmail.com> writes: > > Perhaps as an additional safety feature, Git could refuse to switch > > away from a detached head if the head isn't reachable from any ref, > > and require -f to override: > > > > $ git checkout $sha1 > > $ git commit > > $ git checkout master ;# complain > > $ git checkout -f master ;# ok > > > > Maybe I'm missing something and this all can't be done, but it seems simpler > > than the other options I've seen in this thread. > > I'm not sure about overloading '-f' option, unless we would require > doubled '-f' for overriding both safety checks: checkout from detached > HEAD, and current meaning of forcing a switch even if index or the > working are differs from HEAD. So you would need > > $ git checkout -f -f master > > if you are on detached HEAD and have uncommitted changes (dirty tree > or dirty index).
A dirty index/worktree doesn't necessarily stop you from checking out a different branch head/commit. Only if you have uncommitted changes to a file that also has changes between HEAD and <other_branch>, git refuses to switch. And if you want to keep your uncommitted changes, you want to use -m (3-way merge), not -f (drop changes).
git checkout -f foo ~= git reset --hard && git checkout foo
So -f is most likely _not_ the flag one wants to overload.
Björn