存储/分支/工作副本混淆 [英] Stash/branch/working copy confusion

查看:133
本文介绍了存储/分支/工作副本混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始使用SourceTree和Git,但我仍然对存储/分支和我的工作副本文件感到困惑。我一直无法找到任何明确的东西给我。



我的困惑是关于与分支和窗口有关的文件的工作副本。我期望的事情的工作方式是,我的文件的工作副本也将链接到分支。如果我要切换分支,它会在切换到新分支之前自动保存我的工作副本。如果我要切换回前一个分支,它将再次存储当前的工作副本文件并恢复前一分支中的文件。



使用SourceTree和Git现在有一段时间,看起来很清楚,这不是它的工作原理,而且你的工作副本文件与你的分支完全无关,就像存储器一样。如果您切换到另一个分支,您的选择是手动存储您的工作副本文件,放弃更改或将您的工作文件带到新分支。

,我想知道的是,这是什么理想的工作流程?假设我正在两个不同的分支中同时开发两个功能,并且想不断地来回跳动。我需要记住在每次切换前存储我的工作副本文件,或者有更好的方法吗?

如果我要切换分支,它会在切换到新分支之前自动保存我的工作副本。


都能跟得上! Git不会自动为您保存本地更改。此外,如果您有未提交的更改与您正在检查的分支发生冲突,那么Git不会让您检出有问题的分支。您需要在检出其他分支之前手动丢弃或隐藏它们。


看来我很清楚[ ...]您的工作副本文件是完全独立于您的分支机构,如存储。


是的,并且有充分的理由那。特别是,一个用于存储的用例是在检出错误分支时开始进行更改。然后,您可以通过缓存您的本地更改(从而以干净的工作状态登陆)避免麻烦。

  • 签出正确的分支,
  • 弹出存储以恢复您的本地更改。 b $ b


    假设我正在两个不同分支中同时开发两个功能,并且要不断地来回跳动。我需要记住在每次切换前存储工作副本文件,或者有更好的方法吗?

    是的,在切换到另一个分支之前存储您的更改,然后弹出以前的存储,这将是正常的工作流程。如果你经常切换分支,那确实很乏味,但是如果你从命令行使用Git,你可以定义别名,以便将这些复杂性抽象出来。



    我从来没有使用过SourceTree,但是我可以想象如何存储/检出/弹出可能涉及很多乏味的鼠标点击。显然,SourceTree
    引入了一种称为自定义操作,它允许你定义自己的命令,包括Git命令。你可能想看看它......


    I've started using SourceTree and Git recently, but I am still confused about stashing/branching and my working copy files. I've been having trouble finding anything out there that clarifies things for me.

    My confusion is with regards to the working copy of files in relation to branches and stashes. The way I am expecting things to work is that my working copy of files will also be linked to the branch. If I am to switch branches, it will automatically stash my working copy before switching to the new branch. If I am to switch back to the previous branch, it will again stash the current working copy files and restore the ones from the previous branch.

    After working with SourceTree and Git for a little while now, it appears pretty clear to me that this is not how it works and that your working copy files are completely independent from your branches, as are stashes. If you switch to another branch, your choices are to manually stash your working copy files, discard the changes, or bring your working files with you to the new branch.

    So, what I am wondering is, what is the ideal workflow for this? Say I am developing two features simultaneously in two different branches and want to constantly jump back and forth. Do I need to remember to stash my working copy files before every time I switch or is there a better approach to this?

    解决方案

    If I am to switch branches, it will automatically stash my working copy before switching to the new branch.

    Nope! Git doesn't automatically stash local changes for you. Also, if you have uncommitted changes that conflict with the branch you're checking out, Git won't let you check out the branch in question. You'll need to either discard or stash them "manually" before checking out that other branch.

    it appears pretty clear to me that [...] your working copy files are completely independent from your branches, as are stashes.

    Yes, and there are good reasons for that. In particular, one use case for stashing is when you start doing changes while the "wrong" branch is checked out. You can then get out of trouble by

    • stashing your local changes (thereby landing in a clean working state),
    • checking out the "correct" branch,
    • popping that stash to recover your local changes.

    Say I am developing two features simultaneously in two different branches and want to constantly jump back and forth. Do I need to remember to stash my working copy files before every time I switch or is there a better approach to this?

    Yes, stashing your changes before switching to another branch, then popping a previous stash, would be the normal workflow. If you switch branches often, that can indeed be tedious, but if you use Git from the command line, you can define aliases in order to abstract some of that complexity away.

    I've never used SourceTree myself, but I can imagine how that stashing/checking out/popping can involve quite a lot of tedious mouse clicks. Apparently, though, SourceTree introduced a mechanism called "Custom Actions" that allow you to define your own commands, including Git commands. You might want to look into it...

    这篇关于存储/分支/工作副本混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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