git-stash与git-branch [英] git-stash vs. git-branch

查看:144
本文介绍了git-stash与git-branch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上一个Git问题中,Daniel Benamy正在讨论Git中的工作流程:


我当时在做主人并且犯了一些事情,然后决定暂时搁置这项工作。我支持了一些提交,然后在开始我的垃圾工作之前分支。


他希望将他的工作状态恢复到之前的状态时点,而不会失去他目前的变化。所有的答案以各种方式围绕着,像

  git分支-m主crap_work 
git分支 - m previous_master master

这与 git stash ?我有点困惑,试图看看这个不同的用例在 这里看起来像什么 git stash / p>




@ Jordi Bunster :谢谢,这清除了一切。我想我会认为存储就像一个轻量级的,无名的分支。所以任何东西都可以做,分支也可以,但用更多的话。好!

解决方案

'stash'在您的工作副本上使用未提交的 dirty 并存储它,给你一个干净的工作副本。



它根本不支持。然后,您可以将存储应用于任何其他分支。或者,从Git 1.6开始,你可以这样做:

  git stash branch< branchname> [< stash>] 

在一个新分支上应用存储。

因此,如果您尚未提交错误的分支,那么存储就会很好。



如果您已经犯下了错误,那么您在问题中描述的工作流程是更好的选择。顺便说一句,你是对的:Git非常灵活,并且具有这种灵活性的重叠功能。


In a previous Git question, Daniel Benamy was talking about a workflow in Git:

I was working on master and committed some stuff and then decided I wanted to put that work on hold. I backed up a few commits and then branched from before I started my crap work.

He wanted to restore his working state to a previous point in time without losing his current changes. All of the answers revolved around, in various ways, something like

git branch -m master crap_work
git branch -m previous_master master

How does this compare to git stash? I'm a bit confused trying to see what the different use case here when it seems like everything git stash does is already handled by branching…


@Jordi Bunster: Thanks, that clears things up. I guess I'd kind of consider "stashing" to be like a lightweight, nameless, branch. So anything stash can do, branch can as well but with more words. Nice!

解决方案

'stash' takes the uncommitted, "dirty" stuff on your working copy, and stashes it away, leaving you with a clean working copy.

It doesn't really branch at all. You can then apply the stash on top of any other branch. Or, as of Git 1.6, you can do:

git stash branch <branchname> [<stash>]

to apply the stash on top of a new branch, all in one command.

So, stash works great if you have not committed to the "wrong" branch yet.

If you've already committed, then the workflow you describe in your question is a better alternative. And by the way, you're right: Git is very flexible, and with that flexibility comes overlapping functionality.

这篇关于git-stash与git-branch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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