git:如何创建我当前工作的分支,但留在我的原始分支上 [英] git: How to create a branch of my current work, but stay on my original branch

查看:137
本文介绍了git:如何创建我当前工作的分支,但留在我的原始分支上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个分支(比方说主人),并且我的工作目录有一些变化。我得到的东西工作,但需要大量的清理 - 所以我想保存我当前的工作目录到一个分支,以防万一我需要回去。以后我肯定会删除这个分支。

I'm on a branch (let's say master), and I have some changes in my working dir. I get stuff working, but needing a lot of cleanup - so I'd like to save my current working dir to a branch just in case I need to go back to it. I'll definitely be deleting the branch later.

另外,我想继续在我所在的地方继续使用master。

In addition, I want to continue working on master EXACTLY where I was.

现在我做了:

Right now I do:

# Save to topic branch
git checkout -b working-stuff
git commit -a -m "work in progress"

# go back to master and continue with the state is was in before
git checkout master
git checkout -- .
git reset

稍后,我将删除主题分支。

Later on, I'll delete the topic branch.

所以,上面的内容正是我想要的,但它有点冗长。有没有更简单的方法来做到这一点(除了脚本)?

So, the above does exactly what I want, but its a bit verbose. Is there a simpler way to do this (besides just scripting it)?

推荐答案

您可以使用

You can use

 git stash

手动

From the manual


当您想要记录工作目录和索引的当前状态时使用git存储,但想要返回到清理工作目录。
命令保存您的本地修改,并恢复工作目录以匹配HEAD提交。

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.

使用<$ c $

 git stash apply

或者您可以列出您的隐藏修改:

Or you can list your stashed modifications with:

 git stash list

这篇关于git:如何创建我当前工作的分支,但留在我的原始分支上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆