git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dimitar Bonev <dsbonev@gmail.com>
To: Thomas Rast <trast@inf.ethz.ch>
Cc: git@vger.kernel.org
Subject: Re: Add porcelain command to revert a single staged file to its HEAD state while preserving its staged state
Date: Sat, 4 May 2013 14:13:25 +0300	[thread overview]
Message-ID: <CADeMBopNestsZT4maGr3+tdOBf_Q0ukUbRCbXyucOiZZeHx6nQ@mail.gmail.com> (raw)
In-Reply-To: <87obcryvcw.fsf@hexa.v.cablecom.net>

I think if there was such a command, it could well be common, at least
for me. I am somewhat surprised that  from the three combinations of
resetting index and working dir's states of a file this is the one
that is missing (it is missing at commit level also for what is
worth). Summary table of resetting commands is present at the end of
this article: http://www.progit.org/blog/2011/07/11/reset.html

Here is how I see the workflow for a file: you start with a state that
matches the HEAD state, you modify the file until reaching the point
of a sufficient solution, you mark it as finished work by staging it
for the next commit, now that you have a solution you can start over
from the HEAD state of the file and try to improve it by choosing a
different path of implementation.

My initial thought was to checkout the file, but surprisingly this
reset the staged state also in addition the working dir's state.
Generally git-checkout modifies the working tree, but indeed if you
use its form for a single file and specify a treeish argument it will
"update the index for the given paths before updating the working
tree". I am curious which are the valid use cases for this behavior of
git-checkout and if it was the right thing to do to implement it this
way. In its current form git-checkout does more work than expected by
me:

git checkout HEAD -- targetfile

The above command should have been implemented to reset the working
dir' state of the file only and if one wants to reset its staged state
he could use 'git reset HEAD targetfile'. This gives you more
flexibility (reset one state, the other state or both states),
git-checkout has more consistent behavior (git-checkout a file and
git-checkout a branch keeps your staged changes), and makes harder to
lose your staged changes (there is a reason for a change to be staged
so it should not be so easy to lose it). As the current behavior is
released I guess it couldn't not be (or it should not be at all)
accommodated to the one described above, so at least another
command/option should be added to implement it.

@ThomasRast: 'git show HEAD:targetfile > targetfile' was proposed in
the both links that I provided in the email that your replied to, but
this introduces external dependency to the command interpreter to
output the file unmodified but not every interpreter does this.
PowerShell in particular modifies the encoding of the file, so I get
strange behavior: 'git diff' states that html files are binary ones
and it does not show me the differences; 'git apply' prints 'fatal:
unrecognized input'. I tried your second suggestion 'git commit'
followed by 'git revert', but this reverses the states of all
committed files. I prefer something that applies to a single file,
like git-checkout and git-reset do. Here is a set of commands more
close to what I wish:

git commit -m 'a provisional stable solution'
git checkout HEAD~1 -- targetfile
git commit  --amend -am 'add solution to problem x'

This requires more commands, makes assumptions about making a commit
to a branch, deviates from the rest of git commands about resetting a
file's state (inconsistent git API).

On Sat, May 4, 2013 at 11:58 AM, Thomas Rast <trast@inf.ethz.ch> wrote:
> Dimitar Bonev <dsbonev@gmail.com> writes:
>
>> I have been looking for such a command/option and no one gave me
>> sufficient answer. So this message should be considered as a feature
>> request. I had a situation where I had staged a file with a problem
>> solution in it, then I wanted to experiment with a different solution
>> so I had to revert the file to its HEAD state and I couldn't find a
>> way that preserves the staged state of that file. More discussions:
>>
>> https://groups.google.com/forum/?fromgroups=#!topic/git-users/nYiN-rE_3i0
>>
>> http://stackoverflow.com/questions/16335799/git-porcelain-command-to-revert-a-single-file-to-its-head-state-but-keep-its-sta
>
> Is that a common enough issue to warrant a better solution than
>
>   git show HEAD:targetfile > targetfile
>
> which is how we would do it?
>
> Or more likely,
>
>   git commit -m WIP
>   git revert -n HEAD
>
> which is safer anyway, since it doesn't lose the formerly-staged state
> so easily (you have the reflog in case of any mistakes).
>
> --
> Thomas Rast
> trast@{inf,student}.ethz.ch

  reply	other threads:[~2013-05-04 11:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-04  7:34 Add porcelain command to revert a single staged file to its HEAD state while preserving its staged state Dimitar Bonev
2013-05-04  8:58 ` Thomas Rast
2013-05-04 11:13   ` Dimitar Bonev [this message]
2013-05-04 18:48     ` Jonathan Nieder
2013-05-04 19:56   ` Junio C Hamano
2013-05-04 20:01     ` Junio C Hamano
2013-05-04 22:46       ` Dimitar Bonev
2013-05-06  9:51         ` Thomas Rast
2013-05-06 14:52         ` Junio C Hamano
2013-05-07 20:39           ` Dimitar Bonev

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=CADeMBopNestsZT4maGr3+tdOBf_Q0ukUbRCbXyucOiZZeHx6nQ@mail.gmail.com \
    --to=dsbonev@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=trast@inf.ethz.ch \
    /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).