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)?
do a merge to get the change then cancel the merge but keep modification:
git merge --no-ff feature
git reset HEAD~1
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.
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 -
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With