ChumboChappati
ChumboChappati

Reputation: 1544

Azure Git: How not to select some files for merge

I am working with Azure DevOps Git. I have a repo with 2 branches Development and Release. I made 5 changes in Release branch, all in different folders, all in different commits. Now I need to merge only 3 of those changes to Development branch i.e. 2 of those changes should not be merged into Development branch. How can I do that?

In Azure web page, I went to my repo, click on Pull requests link to open it, then click on New Pull request button to start creating new Pull request. Then for source branch I select Release branch, and for target branch I select Development branch. Its Files tab shows 5 files. But I dont see any option to not select any of them.

Upvotes: 0

Views: 7170

Answers (2)

LeGEC
LeGEC

Reputation: 51850

If you never ever want these changes in Development, you can revert those two specific changes, and merge that in Development :

in your local repo :

  • from the Release branch

  • create a new branch (choose a name, I will call it wip)

  • on this branch, revert the two commits you want to skip :

     git revert <hash of commit1>
     git revert <hash of commit2>
    
  • push this branch to devops :

     git push -u origin wip
    

on DevOps :

  • create a new Merge Request, asking to merge wip into Development

Upvotes: 0

Ron
Ron

Reputation: 441

The comment from Pranav Singh would be the best option, cherry-picking. When you create a PR you are merging one branch into another. If you are only wanting to merge part of the changes I would make a new branch based off the default branch and then cherry-pick the changes into that new branch. You do not want to cherry-pick from one branch into the default branch as that defeats the purpose of a PR.

https://git-scm.com/docs/git-cherry-pick The raw git manual is a great resource but sometimes hard to read through.

Sometimes it is easier to read here https://www.atlassian.com/git/tutorials/cherry-pick

I would say also then make sure to merge or rebase the default branch into the original branch (where you cherry-picked from) once you complete the PR. This way if it causes any Merge conflicts you can address them sooner than later.

Upvotes: 1

Related Questions