5 ms·
Some useful commands I'd use in scenarios like this are: git add -p # select what to add to the staging area git reset -p # deselect chunks that I decided
by maccam94 9y ago
Some useful commands I'd use in scenarios like this are:
git add -p # select what to add to the staging area
git reset -p # deselect chunks that I decided I don't want anymore
git stash # saves your working state in a temporary commit (not in your branch)
git stash pop # restores the working state from the last git stash command and drops the temporary commit
git rebase -i $start_point # where $start_point is either a branch or some commit in your branch history. -i means interactive, which allows you to reorder/edit/reword/squash commits
git checkout -b $newbranch $start_point # you can make a new branch at any commit in history, so if you decide to reorder your commits, then declare and older commit as a branch and get it merged first, that's fine. $start_point is optional, if unspecified the current HEAD commit is used.
For your specific example, with a staged partial commit on branch idea-1, I would:
git commit -m 'WIP idea 1'
git checkout -b idea-2 HEAD~1 # makes a new branch at the parent of the HEAD commit
git add -p # pull in the desired changes
git commit -m 'idea2 implementation'
git checkout idea-1
git add -p # stage the rest of the changes
git commit --amend
git rebase idea2 # if idea 1 depends on idea 2
I do wish git had some notion of sub-commits with their own messages, and a better UX for cleaning up a set of commits before merging them.
- mmebane 9y ago> I do wish git had some notion of sub-commits with their own messages You could use the "fast-forward with merge commit" style. [1] Then you can treat the commits from the branch as sub-commits, and the merge commit as the parent commit. [1]: https://stackoverflow.com/questions/15631890/how-to-achieve-git-no-ff-ff-only-which-is-not-allowed https://stackoverflow.com/questions/15631890/how-to-achieve-...
- maccam94 9y agoInteresting! That's almost what I want, except here's the specific behavior I want to achieve: A clean git log view that shows only meta-commits Git blame shows both the meta-commit and the sub-commit for each line I suppose I could get creative by enforcing that tags be embedded in commit messages and then filtering them in the log view, but it would be better if it was standard.
- mmebane 9y agoYou can show only merge commits with git log --merges However, I don't know if there's any way to achieve that with git blame, and not all tools may offer that kind of log view.
- wutbrodo 9y ago> I do wish git had some notion of sub-commits with their own messages, and a better UX for cleaning up a set of commits before merging them. Does rebase -i handle this adequately or am I misunderstanding what you're describing here? My workflow sounds like exactly what you're saying here, where "subcommits" are my development commits and the UX is the rebase -i editor.
- maccam94 9y agoSee my reply to mmebane about sub-commits. Re: UX, specifically the patch editor (git add/reset -p) is sometimes difficult to use. For example, I've had issues with changes that happen around empty lines refusing to apply for unknown reasons.