git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* tools for easily "uncommitting" parts of a patch I just commited?
@ 2016-10-19 22:26 Jacob Keller
  2016-10-19 22:42 ` Jeff King
  0 siblings, 1 reply; 16+ messages in thread
From: Jacob Keller @ 2016-10-19 22:26 UTC (permalink / raw)
  To: Git mailing list

Hi,

I recently (and in the past) had an issue where I was using git add
--interactive and accidentally did something like the following:

# hack lots of randmo changes, then begin trying to commit then separately
git add -i
# set only the changes I want
# accidentally add <file> to the commit
$git commit -s <file>
# type up a long commit message
# notice that I committed everything

At this point I'd like to be able to do something like:
$git unstage -i
# select each hunk to unstage

and end up with a commit that only has what I originally wanted,
without having to re-write the commit message, nor having to do a lot
of weird things, or anything.

I can ofcourse use reset HEAD^ and lose my commit message, but then
I'd have to retype that out or copy paste it from somewhere else.

I ended up doing something like:

# save the current tree
$git rev-parse HEAD >savetree
# checkout the old files and re-write
$git checkout HEAD^ <file>
# update commit removing all changes from this file
$git commit --allow-empty --amend <file>
# now checkout the tree again to the contents of the saved tree
$git checkout $(cat savetree) <file>
# now add only the parts I wanted before
$git add -i
# finally amend the commit
$git commit --amend

That's a lot of steps and forces me to save my own file.

I thought of a few alternatives:

1. Create an advice setting which basically allows me to say "git,
please prevent me from staging files + an index if the files I marked
also conflict with paths already added to the index, maybe unless I
passed a force option"

or

2. somehow streamline the process of what I did above so I could just
do something like:

git commit --amend --set-tree=HEAD^

which would force the commit tree up one and avoid the double checkout
stuff, without actually changing my checked out copy at all

Then I'd be able to quickly re-add what I wanted.


3. somehow allow an unstage option.

So for the TL;DR; .. does anyone know of any tools which would help
automate the process so I could simply do

"git uncommit -i" and run a tool just like git add interactive or git add -p?

Thanks,
Jake

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2016-10-23 10:28 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-19 22:26 tools for easily "uncommitting" parts of a patch I just commited? Jacob Keller
2016-10-19 22:42 ` Jeff King
2016-10-19 23:36   ` Jacob Keller
2016-10-20  2:13     ` Jeff King
2016-10-20  5:53       ` Jacob Keller
2016-10-20 16:30       ` Junio C Hamano
2016-10-20 17:27         ` Jacob Keller
2016-10-20 17:39           ` Junio C Hamano
2016-10-20 18:13             ` Jacob Keller
2016-10-20 18:41               ` Junio C Hamano
2016-10-20 20:03                 ` Jacob Keller
2016-10-22  9:19           ` Lukas Fleischer
2016-10-23  1:07             ` Jacob Keller
2016-10-23  1:23             ` Duy Nguyen
2016-10-23  1:38               ` Jeff King
2016-10-23 10:27                 ` Duy Nguyen

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).