Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Break up multiple changes into separate commits with git?

Tags:

git

If I have made multiple sets of changes to a large file, is it possible to split those into separate commits using git?

like image 287
markdorison Avatar asked Feb 09 '11 17:02

markdorison


People also ask

What is git split?

Workflow for Splitting git Commits When git presents the commit that you want to split: Reset state to the previous commit using git reset HEAD^ Use git add to carefully and incrementally add changes to the index. Run git commit when you have a set of atomic changes that you are ready to commit.

What is git squash?

To "squash" in Git means to combine multiple commits into one. You can do this at any point in time (by using Git's "Interactive Rebase" feature), though it is most often done when merging branches. Please note that there is no such thing as a stand-alone git squash command.

How do you reset a squash commit?

You can do this fairly easily without git rebase or git merge --squash . In this example, we'll squash the last 3 commits. Both of those methods squash the last three commits into a single new commit in the same way. The soft reset just re-points HEAD to the last commit that you do not want to squash.


2 Answers

You want git add --patch (documentation), which will allow you to select which changes to stage.

like image 114
William Pursell Avatar answered Sep 28 '22 19:09

William Pursell


Yes, you can -- use git add -i to select which hunks you want to stage for each commit. You can get documentation by running git help add and scrolling to "Interactive Mode".

like image 28
Andrew Aylett Avatar answered Sep 28 '22 17:09

Andrew Aylett