1

So far I'm using the Git Workflow. I've seen a lot of documentation about it using the "Ideal happy world" solution, but not realistic scenarios.

Git Workflows is very straightforward: create a release branch from Develop and merge into master.

But what happens IF you have, let's say 10 commits in develop, and you want only 3 random commits to be released (the other 7 didn't pass the testing or are still being tested). As far as I see you have 2 options:

  1. Create a release branch from develop and revert the 7 unwanted commits
  2. Create a release branch from master and cherry-pick the 3 chosen commits from develop branch.

I haven't seen any good enough explanation for this.

I'm using the 1) approach but it gets hard when you have to revert many commits, and approach 2) gets hard when there are no commits to revert.

The way we use it: When the feature is approved and merged into Develop it gets deployed in QA environment, only successfully tested stories are moved into the release branch, Release branch is deployed into Production, if it successful it gets merged into Master.

Erick P
  • 21
  • 2

3 Answers3

0

Your explained two solution should work. But their is another simple way to do this using revert command for the commit whose are wanted to remove.[The revert command will create a new commit with the undo of the original commit.]

Checkout the desired branch

git checkout "branchName"

Undo the desired commit

git revert "commit_id"

Update the remote with the undo of the code

git push origin "branchName"

Then you can merge the updated pull request.

RafsanJany
  • 355
  • 1
  • 10
0

If you have pushed to the remote server, then using git reset is not a great idea, as other users probably may have this commit in their local repository now, and might be making edits and then afterwards they will not see the committed code, in which they worked on. If you use git revert the other users will see what you have committed which is the commit you want to be removed, and your comment should explain why. This is more clear and less disruption for the other users working on the same project.

Shaqil Ismail
  • 1,794
  • 1
  • 4
  • 5
0

@Erick. Your second approach is the commonly used one. One more way is through squashing.

Squashing example: Showing for 5 patches, where I choose 2 good patches to my release branch.

$git branch my_release_branch // Create release branch from development branch.

$git checkout my_release_branch // Checkout to release branch.

$git rebase -i HEAD~5 // Squash 5 commits from the tip.

Once you enter, you may choose to keep or drop the commits here.

pick 9729c8db8fa my_good_patch1 // pick the good one.

drop 8729c9db8fb my_bad_patch1 // drop the bad one.

pick 7729c7db8fc my_good_patch2

drop 6729c6db8fd my_bad_patch2

drop 5729c5db8fe my_bad_patch3

Save your selection, then let git will squash and update the release branch.