Re:Git-absorb: Git commit –fixup, but automatic
by kccqzy on Wednesday September 25, 2024 @09:23PM
(#41653575)
If it only lets you select one, that's strictly less powerful. What if I want some parts of it into one commit and another parts into another? The `hg absorb` works for this case.
[ Parent
| on HN ]
Re:Git-absorb: Git commit –fixup, but automatic
by k3vinw on Wednesday September 25, 2024 @11:02PM
(#41654117)
Might be able to use the multimode flag in the fzf command above and it should let you select more than one using Tab and Shift+Tab.
Re:Git-absorb: Git commit –fixup, but automatic
by kadoban on Wednesday September 25, 2024 @10:41PM
(#41654003)
That sounds like what `git add -p` is for, stage part of the current changes.
Re:Git-absorb: Git commit –fixup, but automatic
by kccqzy on Thursday September 26, 2024 @11:00AM
(#41659177)
That still requires you to manually select hunks. The point of `hg absorb` is to automatically select hunks even if these hunks are to be squashed into different commits.
Re:Git-absorb: Git commit –fixup, but automatic
by account42 on Monday September 30, 2024 @05:27AM
(#41695192)
"Automatic" sound like it would fail about as often as it would help.
Re:Git-absorb: Git commit –fixup, but automatic
by atq2119 on Thursday September 26, 2024 @04:56AM
(#41656106)
Then you use `git gui`, which is part of the git distribution itself, or `tig` if TUIs are your thing. I have a key binding for `git commit --squash=%(commit)` in my tig config, so I can interactively select lines or hunks to stage and then the target commit for the squash.
Re:Git-absorb: Git commit –fixup, but automatic
by AndrewHampton on Thursday September 26, 2024 @07:30AM
(#41657120)
Yeah, it's definitely less powerful that what absorb is doing. I wasn't trying to argue that it was equivalent. I just wanted to share a bash one-liner that I've had success with in case others find it helpful.
> What if I want some parts of it into one commit and another parts into another?
Looks like absorb will automatically break out every hunk into a separate fixup commit. My one-liner will create 1 fixup commit for everything that's staged. That's typically what I need, but on the occasions it's not, I use `git add -p`, as kadoban mentioned, to stage exactly what I want for each commit.
Re:Git-absorb: Git commit –fixup, but automatic
by mst on Thursday September 26, 2024 @09:07AM
(#41657951)
Oh, hrm, looking at this description and the one liner, I rather like.
Once you mentioned `git add -p` I realised that this is pretty much what I do already, except with a far more efficient way of selecting the relevant commit to do it to.
Muchas gracias.
Re:Git-absorb: Git commit –fixup, but automatic
by AndrewHampton on Thursday September 26, 2024 @10:13AM
(#41658649)
Yeah, I use about a dozen git aliases in my normal workflow. In case it's helpful, here are the relevant ones for this flow:
alias git_main_branch='git rev-parse --abbrev-ref origin/HEAD | cut -d/ -f2'
alias gapa='git add --patch'
alias grbm='git rebase -i --autosquash $(git_main_branch)'
alias gfx='git commit --fixup $(git log $(git_main_branch)..HEAD --oneline| fzf| cut -d" " -f1)'
Another favorite is: alias gmru="git for-each-ref --sort=-committerdate --count=50 refs/heads/ --format='%(HEAD) %(refname:short) | %(committerdate:relative) | %(contents:subject)'| fzf | sed -e 's/^[^[[:alnum:]]]*[[:space:]]*//' | cut -d' ' -f1| xargs -I _ git checkout _"
gmru (git most recently used) will show you the branches you've been working on recently and let you use fzf to select one to check out.