Here are a few shortcuts in the same vein:
fixup with the default of HEAD: fu = !bash -c 'git commit --fixup ${1:-HEAD}' -
Find the point of divergence of the current branch from another branch (default master), useful for the following trick: diverges = !bash -c 'diff --old-line-format='' --new-line-format='' <(git rev-list --first-parent "${1:-master}") <(git rev-list --first-parent "${2:-HEAD}") | head -1' -
Finally, rebase with autosquash from the point of divergence from another branch (so that you don't have to count the commits):
ar = !bash -c 'git rebase --autosquash -i `git diverges ${1:-master}`'
Note that you can also use git config --global rebase.autosquash=true so that you do not need to add the --autosquash flag to all your git rebase commands.
Nicolai is a thirty year old boy, as the narrator would put it, who has found his passion in software development. He constantly reads, thinks, and writes about it, and codes for a living as well a...
I don't quite get why I wouldn't use the much simpler git amend (alias for git commit --amend) for the simple case of adding to the last commit and only do a rebase (remember no unstaged changes for that, may need to stash!) if I really need it.
That's a matter of personal preference.
I like having the history of minor changes available. I usually only rebase before a git push, and by that time, I try not to have any uncommited changes in any case.
I feel that the little extra typing (which can be saved using @freeatnet
tip here) is worth it for the extra history and for editing previous commits.
Also a nice tip that usually goes along with --fixup is to find the commit with :/ i.e. git commit --fixup :/First will find the last commit with First in its message.
I have great experience in IT over 12 years: front / back - ends, mobile, system administration and deployment cycle. I implement effective and great software products.
Thanks for the article, useful information.
But amend is not evil if you use it in right purposes.
ps: never used amend it fix the history, only for append changes on dev commit.
Here are a few shortcuts in the same vein:
fixup with the default of HEAD:
fu = !bash -c 'git commit --fixup ${1:-HEAD}' -Find the point of divergence of the current branch from another branch (default master), useful for the following trick:
diverges = !bash -c 'diff --old-line-format='' --new-line-format='' <(git rev-list --first-parent "${1:-master}") <(git rev-list --first-parent "${2:-HEAD}") | head -1' -Finally, rebase with autosquash from the point of divergence from another branch (so that you don't have to count the commits):
ar = !bash -c 'git rebase --autosquash -i `git diverges ${1:-master}`'This is great, thanks!
Nice article!
Note that you can also use
git config --global rebase.autosquash=trueso that you do not need to add the--autosquashflag to all yourgit rebasecommands.Thanks!
That's true. Just make sure to add
--no-autosquashto thegit mrialias to get the same behavior.Cool tip!
Just to clarify, it's
git config --global rebase.autosquash true; having the=throws aninvalid keyerror.I don't quite get why I wouldn't use the much simpler
git amend(alias forgit commit --amend) for the simple case of adding to the last commit and only do a rebase (remember no unstaged changes for that, may need to stash!) if I really need it.That's a matter of personal preference.
I like having the history of minor changes available. I usually only rebase before a
git push, and by that time, I try not to have any uncommited changes in any case.I feel that the little extra typing (which can be saved using @freeatnet tip here) is worth it for the extra history and for editing previous commits.
Yes, yes and a thousand times yes!
Developers need to learn to commit often and create small commits for their own safe and their mates.
So huge thank you for spreading the word :)
I also wrote an article on this subject few weeks ago: adopteungit.fr/en/methodology/2017...
Wow, this is great. I am going to immediately modify my workflow in this direction.
Woops, commented from the staff account. ¯_(ツ)_/¯
Another alternative is
git rebase -iand marking the "Added First Module" with "edit". Then make the change, add, commit and rebase --continueAlso a nice tip that usually goes along with
--fixupis to find the commit with:/i.e.git commit --fixup :/Firstwill find the last commit withFirstin its message.Thanks for the article, useful information.
But amend is not evil if you use it in right purposes.
ps: never used amend it fix the history, only for append changes on dev commit.
Cool, haven't used fixup yet.
Just saying if you hate things because they hide history you should fight against rebase too
It's the hiding history while I work part that bothers me.