简体   繁体   中英

Git: How Can I get back to my MASTER without committing?

My master branch is messed. I should have setup branches before now, but I've just realized why I need them!

So, I've got a pile of changes in master that I don't want to commit yet, but I've got some hotfix stuff in a new branch that I want to commit.

How can I put all that stuff in master aside and push a tiny hotfix from a branch?

Basically, I'm not ready to push any of the stuff in the screenshot live yet:

Git主要分支概述

git stash

DESCRIPTION
       Use git stash when you want to record the current state of the working
       directory and the index, but want to go back to a clean working
       directory. The command saves your local modifications away and reverts
       the working directory to match the HEAD commit.

You can also then

git stash list

will show all the stashes you've made, and

git stash clear

if you'd like to just abandon the stashed changes.

As of Git 2.5 (July 2015), you can use git worktree :

git worktree add -b patch-1 ../patch-1

This is essentially just creating a branch, but it puts the new branch into a new folder alongside the parent repo. This is nice because you can do work on this branch, even without committing, then switch back to master with a clean working directory.

Maybe I am misunderstanding, but couldn't you just REVERT your master back to a less screwy time, then commit your hotfix changes. If I understand you, that's what I'd do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM