News for hackers. Stuff that matters.
Re:Some bad Git situations and how I got myself out of them by mhw on Friday September 09, 2016 @08:27AM (#12461476)
One of the nice workflows that's already built in to the git command line tools is this one. When you're working on a branch and realise that a commit you made a few commits back has a mistake in it:

    # Make correcting change
    git commit --all --fixup=<ref of commit with mistake>
    # Continue working on branch, then at some point
    git rebase --interactive --autosquash
The --fixup option creates commits with subjects formatted like 'fixup! previous commit subject'. --autosquash uses these subjects when building the interactive rebase list.

Handy enough that I set rebase.autoSquash to true in my ~/.gitconfig so 'git rebase -i' always works like this.

Re:Some bad Git situations and how I got myself out of them by bennofs on Friday September 09, 2016 @09:33AM (#12461992)
Even better in combination with the `:/grep` syntax that allows you to specify the commit by grepping the commit messages, prefering more recent commits: `git commit --all --fixup ':/implement some feat'`.
Re:Some bad Git situations and how I got myself out of them by mhw on Friday September 09, 2016 @10:20AM (#12462435)
Mmm - nice. Glad I posted it now, as I didn't know that variation!
Re:Some bad Git situations and how I got myself out of them by dahart on Friday September 09, 2016 @09:52AM (#12462166)
Yeah, super useful, I can second setting auto squash in the config. I was almost thinking of saying the same thing, but I realized this post is probably deliberately avoiding rebase. This workflow is advanced relative to the problems described, and you'd agree those command lines are going to look pretty intimidating to a novice, right? They were to me the first time, there's a lot to understand before they're comfortable.
Re:Some bad Git situations and how I got myself out of them by mhw on Friday September 09, 2016 @10:26AM (#12462494)
> This workflow is advanced relative to the problems described

Yeah, true. I posted it mostly because one of the bigger threads of comments was advocating using a GUI instead of the CLI. I'm not going to argue that the git CLI is simple, but it does have some nice features to support specific common workflows.

Re:Some bad Git situations and how I got myself out of them by aromatt on Friday September 09, 2016 @12:43PM (#12463858)
Yep. I find that most of the time, the commit I want to fixup is my last one, so I don't even need the interaction. I use this script almost every day:

    last_commit=$(git log --oneline | head -1 | cut -d' ' -f1)
    git commit -a --fixup ${last_commit}
    GIT_SEQUENCE_EDITOR=true git rebase -i --autosquash ${last_commit}~1
Re:Some bad Git situations and how I got myself out of them by bjackman on Friday September 09, 2016 @12:57PM (#12464017)
What's the difference between this and 'git commit --amend'?
Re:Some bad Git situations and how I got myself out of them by aromatt on Friday September 09, 2016 @01:21PM (#12464246)
I'd say my script is equivalent to `git commit --all --amend --no-edit`