Git: move changes off of master branch

后端 未结 6 458
南旧
南旧 2021-02-03 20:53

Basic question but this happens to me all the time:

  • Make changes in a working-branch
  • Switch to master
  • git merg
6条回答
  •  生来不讨喜
    2021-02-03 21:16

    Get in the habit of typing $ git status before you actually do a git command that will modify something.

    Given that, you have probably edited your file but not checked it in, because you would run git status before the commit. In this case, git does the right thing if you just switch branches, then commit.

    If you have fired a commit off to master, then just move the file between branches with something like this:

     $ git checkout --patch master 
    

    You don't really have to reset master if you are just going to merge the same file with it, but since presumably you haven't pushed anything yet you should just reset to your remote tracking branches...

    $ git reset master origin/master
    $ git reset stage origin/stage # whatever
    

提交回复
热议问题