gittortoisegit

Splitting a commit in Git


I'm really new to Git (and we're using TortiseGit), but here's my issue. I have 3 environments: Dev, QA and Production. The client requested two changes so I made both changes in Dev, committed them and pushed it to the QA environment. Now the company wants one change to go to Production now and the next one to wait on a change to another system. How do I push just part of the commit to Prod?


Solution

  • Commits themselves are atomic, so they can't be split or broken up. However since a commit is just a collection of changes, we can split up those changes and then create separate commits that just include the changes that you would want for each.

    One way of doing this is to just do a soft reset to the commit before the one that you would want to split up, then stage each set of changes and commit separately.

    If you already pushed your commits before breaking them up. You would need to do a force push because you're replacing the old commit with the broken down commits so make sure to pull before doing any changes.

    Agree'd with PeeHaa, you would want to create different branches for each environment and then you could just cherry pick the desired commits.