moving changed files to another branch for check-in

前端 未结 4 1644
独厮守ぢ
独厮守ぢ 2020-12-22 15:24

This often happens to me: I write some code, go to check in my changes, and then realize I\'m not in the proper branch to check in those changes. However I can\'t switch to

4条回答
  •  悲哀的现实
    2020-12-22 16:23

    A soft git reset will put committed changes back into your index. Next, checkout the branch you had intended to commit on. Then git commit with a new commit message.

    1. git reset --soft

    2. git checkout

    3. git commit -m "Commit message goes here"

    From git docs:

    git reset [] [] This form resets the current branch head to and possibly updates the index (resetting it to the tree of ) and the working tree depending on . If is omitted, defaults to --mixed. The must be one of the following:

    --soft Does not touch the index file or the working tree at all (but resets the head to , just like all modes do). This leaves all your changed files "Changes to be committed", as git status would put it.

提交回复
热议问题