Andrii Zymohliad Andrii Zymohliad - 10 months ago 67
Git Question

git - Get changes from another branch without affecting current branch at all

Is there a simple way to get changes from another branch without merge or rebase. And keep those changes as untracked (for new files) or not staged for commit (for existing files)?

Answer Source

You could use git cherry-pick -n <commit>.... It takes the changes from one or more commits and applies them to your current working tree without making a commit.

Documentation for -n flag:



Usually the command automatically creates a sequence of commits. This flag applies the changes necessary to cherry-pick each named commit to your working tree and the index, without making any commit. In addition, when this option is used, your index does not have to match the HEAD commit. The cherry-pick is done against the beginning state of your index.

This is useful when cherry-picking more than one commits' effect to your index in a row.