For some reason I want to abandon my branch_A but I have some files just committed in that branch_A. I want to add them to branch_B.
How can I do that?
For some reason I want to abandon my branch_A but I have some files just committed in that branch_A. I want to add them to branch_B.
How can I do that?
 
    
     
    
    Switch on the branch B:
git checkout branch_B
Then, checkout the files you want to keep:
git checkout branch_A file1 file2 file3 [...]
At last, commit your changes
git commit -m "Backport changes from branch A for reasons"
 
    
    If you're confused on how to execute right commands in console which was proposed above, then you have a lazy, easy option:
1) Copy your files out of your project directory 2) Checkout to your branch_B 3) Replace your copied files with checked-out ones, you can even merge them 4) Commit the change
 
    
    git reset HEAD^ will move you one commit back. ie. just before you made the commit onto branch_A. Now switch to branch_B using git checkout branch_B. Then git add the files you want to commit and then git commit them. They will be on branch_B.
 
    
    Switch on branch_A: git checkout branch_A , use git log and record your commit id. Then switch on branch_B :git checkout branch_B and use git cherry-pick your commit id to move the commit into branch_B.
 
    
    to selectively add changes from another branch
git checkout --patch other_branch file1 file2
