Apply stash to another branch

I accidentally worked on the wrong branch. Now I want to push all my changes to the correct branch.

If I close the changes and apply them in the correct branch, will it only add uncommitted changes to the correct branch or every change / commit from the wrong branch that does not exist in the correct branch?

for instance

The wrong branch has:

  • Commit

  • Unfixed changes b

The correct branch has

  • Commit c

If I do git stash on the wrong branch and git apply stash on the correct branch, will it pass commit a to the correct branch?

+5
source share
4 answers

I would make one cache, then reset (mix so you don't lose the changes), commit, stash, and then change the correct branch and put both stamps.

git stash save "b" git reset HEAD~ git stash save "a" git checkout correct-branch git stash pop git commit -m "a" git stash pop 
+5
source

Bypass

  • Make a commit with these desired changes.
  • Make a purchase at the branch in which you want these changes to be included.
  • From this git cherry-pick 23h123kjb (<- replace this hash with the one found in the git log specific to the commit you want to make)
  • Profit!
+2
source

If your branch does not exist yet:

  • git branch "new_branch"

if:

  • git cache branch "temp_new_branch"
  • git add "your changes"
  • git commit
  • git checkout "your desired branch to apply stash"
  • git merge "temp_new_branch"
  • git click
  • git branch -d "temp_new_branch"
+2
source

No, it will not. Entries do not fit into Stash. I also sometimes just switch branches with my changes uncommitted and blurry, and it also works (not sure if in each case, though).

+1
source

All Articles