Git cherry picking and commits

Viewed 377

I'm trying to migrate parts of a feature branch into the main application. The feature branch was part of a prototype that had diverged from master a while back.

Feature --> A --> B --> C --> D ---> E

Master --> many changes on prototype --> feature

e.g. I'm after C, D, E. I'm having a problem where there's were many commits of a file that requires many conflict resolutions. E.g. commits C, D, E are all for a file (let's call it file A). After reading the Atlassian page on git commits:

"Whereas SVN tracks differences of a file, Git’s version control model is based on snapshots. For example, a SVN commit consists of a diff compared to the original file added to the repository. Git, on the other hand, records the entire contents of each file in every commit"

It seems that I can pull the last commit i.e. the commit E and receive all changes to file A? Without git cherrypicking C and D and having to fix merge conflicts three times?

The only down side I can see from this is if there were multiple file changes in the earlier commits e.g. Commit D had File A and File B but File B wasn't committed again in D or E. Then I could be missing File B.

Is my understanding correct? I'm am trying to complete this merge in a more efficient way.

Cheers

1 Answers

First of all, it seems unclear what you are trying to achieve here.

From my understanding, you want to add all your commits from the feature branch to the main branch. The best way to achieve the same is to do a git pull and then git rebase, if there are any merge conflicts git will ask you to solve them before the merge. There is not better way than this.

If you will attempt to a cherry-pick of only the last commit E, git will just add the changes from commit E only, without considering any changes made before.

Related