Link to a different branch without touching uninstalled files

I have two branches, say B1 and B2. I am in B2 and I have installed and uninstalled files.

I want staggered files to be committed to B1 (I thought I was in B1 when I git add

-ed files) and unset to be committed to B2.

Is it possible? How?

+3


source to share


3 answers


git stash

really efficient when pushing dirty changes between branches. In your case, you can apply the following steps:

  • git stash --keep-index

    , this will only close unset files
  • git stash

    , this will write the rest, i.e. supplied files
  • switch to B1
  • git stash pop

    , the staged files will be moved to B1
  • switch to B2
  • git stash pop

    , uninstalled files will be transferred to B2


After that, you can commit changes to each branch individually.

+3


source


I'm sure there is a more elegant way, but all I could come up with is this:

  • Commit the delivered files for B2
  • Set up non-stationary work on B2
  • Switch to B1 then cherries select the last commit of B2 to B1
  • Go back to B2, reset to last post (--hard way)
  • Scene and copy folded work to B2


EDIT

This question has a detailed answer that does more or less what I suggested.

+3


source


If the modified staged and unset files don't change by switching to branch B1, you can switch branches without affecting anything, then you can easily transfer your files and switch back to B2.

However, if your modified files are changed between B1 and B2, you cannot switch branches. In this case, you need to commit your changes before deploying branches.

  • git stash --keep-index

    to save and save phased files
  • git reset HEAD

    for non-installation staged files
  • git stash

    to keep your previous staged files.
  • git checkout B1

    to go to branch B1
  • git stash pop

    to unlock and remove the last stash
  • git commit -a

    to commit your previously delivered files to B1
  • git checkout B2

    to go to branch B2
  • git stash pop

  • git commit -a

    commit all other changes to B2

Be careful with these commands! I'm not a git pro! :-)

+1


source







All Articles