Practical uses of git reset --soft?

后端 未结 11 2037
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 16:24

I have been working with git for just over a month. Indeed I have used reset for the first time only yesterday, but the soft reset still doesn\'t make much sense to me.

11条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 16:40

    One possible usage would be when you want to continue your work on a different machine. It would work like this:

    1. Checkout a new branch with a stash-like name,

      git checkout -b _stash
      
    2. Push your stash branch up,

      git push -u origin _stash
      
    3. Switch to your other machine.

    4. Pull down both your stash and existing branches,

      git checkout _stash; git checkout 
      
    5. You should be on your existing branch now. Merge in the changes from the stash branch,

      git merge _stash
      
    6. Soft reset your existing branch to 1 before your merge,

      git reset --soft HEAD^
      
    7. Remove your stash branch,

      git branch -d _stash
      
    8. Also remove your stash branch from origin,

      git push origin :_stash
      
    9. Continue working with your changes as if you had stashed them normally.

    I think, in the future, GitHub and co. should offer this "remote stash" functionality in fewer steps.

提交回复
热议问题