|
|
Subscribe / Log in / New account

Hmm …

Hmm …

Posted Nov 6, 2018 6:28 UTC (Tue) by smurf (subscriber, #17840)
In reply to: Hmm … by epa
Parent article: Apache Subversion 1.11.0 released

Grouping commits is reasonably simple – you create a branch for them, and then do a non-fast-forward merge to the parent.


to post comments

Hmm …

Posted Nov 6, 2018 7:08 UTC (Tue) by epa (subscriber, #39769) [Link] (2 responses)

Yes, as I mentioned you can get some of the benefits by merging a branch in one commit. But that forces a nonlinear history, while allowing nested changes would still give a linear timeline for bisecting, etc.

Also it only really gives one level of nesting and is a bit clunky. Take for example the problem mentioned in an earlier post. To rename a file you may first do ‘git mv’ in one commit then change the contents in the next. Does anyone really land a separate branch just for that? What I envisage is something like ‘git group open; git commit; ...; git group close’. On closing the group you are prompted for a top-level commit message. Or you could group commits when rebasing. This would be similar to the current support for squashing commits into one, but still allowing the individual changes to be retrieved if you choose to ‘look inside’.

Hmm …

Posted Nov 6, 2018 19:44 UTC (Tue) by MrWim (subscriber, #47432) [Link] (1 responses)

Put this in git-group.sh, mark it executable and run git config --global alias.group '!/path/to/git-group.sh'. You will then be able to run git group open and git group close. It's a quick and dirty hack, with precious little error handling, but it will support nesting and should be convenient to use.

If you want to get a log with these groups collapsed run git log --first-parent.

git-group.sh follows:

#!/bin/sh -e

fail() {
    echo $@ >&2
    exit 1
}

current_branch=$(git symbolic-ref --short HEAD)

cmd=$1
shift

case "$cmd" in
open)
    git checkout -b ${current_branch}-group
    ;;

close)
    parent=$(echo $current_branch | sed 's/-group$//')
    [ "$parent" != "$current_branch" ] || fail "Not in a group!"
    git checkout "$parent"
    git merge --no-ff --no-commit --log "$current_branch" --edit
    printf '# Enter top-level commit message here.  Sub-commit messages follow:\n\n' >.group_commit_msg
    git log --first-parent --format=%B "${parent}...${current_branch}" >>.group_commit_msg
    git commit --file .group_commit_msg --edit
    rm .group_commit_msg
    git branch -D "$current_branch"
    ;;

*)
    fail "Unknown command $cmd"
    ;;
esac

Hmm …

Posted Nov 6, 2018 20:08 UTC (Tue) by epa (subscriber, #39769) [Link]

Thanks!


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds