Get changes from another branch without affecting current branch at all

You can use git diff <another-branch> ^HEAD to print a diff of the changes that are in "another-branch", but not in your current branch (HEAD). And then apply those changes to the current index by passing them to git apply -.

git diff <another-branch> ^HEAD | git apply -

git cherry-pick -n <commit>...
git reset

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

Documentation for -n flag:

-n

--no-commit

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.

git reset will remove picked files from staging.


do a merge to get the change then cancel the merge but keep modification:

git merge --no-ff feature
git reset HEAD~1

Tags:

Git