Retrieve changes from another branch without affecting the current branch at all

Is there an easy way to get changes from another branch without merging or redirecting. And save these changes as not checked (for new files) or not set for fixing (for existing files)?

+9
source share
6 answers

You can use git cherry-pick -n <commit>... It accepts changes from one or more commits and applies them to the current working tree without committing.

Documentation for the -n flag:

-n

- no fixation

Typically, a command automatically creates a sequence of commits. This flag applies the changes necessary for cherry to choose each name, fix your working tree and index without committing. Also, when this parameter is used, your index should not match the HEAD commit. Cherry picking is done against the beginning of the state of your index.

This is useful when cherry picking more than one effect makes your index in a row.

+13
source

merge to get the change, then undo the merge, but save the modification:

 git merge feature git reset HEAD~1 
+8
source

This requires your working tree to be clean (there were no changes from the HEAD commit) 1 .

 git cherry-pick <commit> git reset --soft HEAD~1 git reset . 

Applies changes from another branch to your current branch if a commit exists, if new files are not checked and existing files are not installed.


If you are interested in learning how to apply changes from another branch in another repository to your current repository. It can be done here .

+2
source

To get changes without merging, you can use:

git fetch

to capture changes without changing the current branch .

+1
source

Place an order from your current branch and pull from another branch. This pulls all commits from another branch to the current branch. You can work with all changes without making changes to the current branch. If you wish, you can commit and click if these changes need to be tracked.

 git checkout <current branch> git pull origin <another branch> 

 git commit git push HEAD 
0
source

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

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

Source: https://habr.com/ru/post/1258789/


All Articles