I think 'git add -p .' would have worked better for the specific example he gave, though. (Step through and stage change by change)
as i said in my other comment. that will only work for idempotent things: if you like to change, say, ' to ", the workflow in the article works, but git add -p won't.
The second-order-diff Git trick
31–40 of 44 posts
Re: The second-order-diff Git trick
#32I find it easier anyway. But the stash approach is interesting, thanks for sharing!
Re: The second-order-diff Git trick
#33I tend to 'git commit' and then 'git commit --amend' until I'm happy, then push to others. I find it easier anyway. But the stash approach is interesting, thanks for sharing!
In the authors example if he got it wrong and it replaced a load of non-links with links then running it again on the output of the first run isn't going to do any good. So he's suggesting replacing "git reset" with "git stash", both reset the repo to the way it was pre-sledgehammer but "git stash" also keeps around the previous results for comparison.
Re: The second-order-diff Git trick
#34I tend to 'git commit' and then 'git commit --amend' until I'm happy, then push to others. I find it easier anyway. But the stash approach is interesting, thanks for sharing!
That's good advice for a lot of situations but it depends if your "sledgehammer" is assuming a certain starting condition. In the authors example if he got it wrong and it replaced a load of non-links with links then running it again on the output of the first run isn't going to do any good. So he's suggesting replacing "git reset" with "git stash", both reset the repo to the way it was pre-sledgehammer but "git stas…
That'll teach me to 'scan read' and then comment!
Re: The second-order-diff Git trick
#35Create a local branch, apply the sledgehammer, and start reviewing changes. Use 'git diff master...' to review changes. (This is short for 'git diff master...HEAD' which in turn stands for 'compare current branch's HEAD with the commit on master off of which you've branched.) 'git add -p' and commit changes that you like.
Iterate until you're happy with the result. You will have ended up with a few commits on your local branch. Use 'git rebase -i master' to squash all commit in a single one. Finally, check out the master branch and merge your local branch in, preferably with --ff.
Re: The second-order-diff Git trick
#36Re: The second-order-diff Git trick
#37alias gqc="git commit -m 'quick commit'"
The command is usually preceded by "git add ." (or alias "ga."). Making a commit ends up being more reliable for me than stash. Also, the commit stays with the branch, making it easy to switch to master branch, make or check an important change, then go back to what I was working on in the develop branch. Additionally, it makes rebasing a work in progress easier. Just gqc && git pull --rebase.
When it comes time to push, I can just check the log for all the "quick commit" commits. If there's just one, then I make an amend commit. If there's more than one, I rebase interactively.
I suppose I could add a hook to make sure I never accidentally push a quick commit, but it hasn't been an issue yet (over the past year or so I've only made the mistake once).
Re: The second-order-diff Git trick
#38Earlier quoted context omitted.
Because then git would be doing magic stuff you don't (necessarily) understand, and people who like that aren't git's target audience. Those are all separate pieces of functionality that shouldn't be stuck together by default.
The same argument could be applied against git pull, which is really the concatenation of fetch and merge (or rebase). I agree with the previous poster that there should be better defaults available to non-tweakers.
Re: The second-order-diff Git trick
#39I think 'git add -p .' would have worked better for the specific example he gave, though. (Step through and stage change by change)
Re: The second-order-diff Git trick
#40I think 'git add -p .' would have worked better for the specific example he gave, though. (Step through and stage change by change)
The reason I don't use `git add -p` to incrementally approve the "good" changes is that the sledgehammer is not incremental: it expects to be applied to the original clean slate. Using git stash will get me back to that clean slate. Using `git add -p` will not, for both the approved and unapproved changes will remain in the working tree, where the sledgehammer expects neither of them to be.