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

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

问题描述

我最近开始使用 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.

在使用 SourceTree 和 Git 一段时间后,我很清楚这不是它的工作方式,并且您的工作副本文件完全独立于您的分支,存储也是如此.如果您切换到另一个分支,您的选择是手动隐藏您的工作副本文件、放弃更改或将您的工作文件带到新分支.

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.

不!Git 不会自动为您存储本地更改.此外,如果您有未提交的更改与您检出的分支冲突,Git 不会让您检出有问题的分支.在检查其他分支之前,您需要手动"丢弃或隐藏它们.

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

  • 隐藏您的本地更改(从而进入干净的工作状态),
  • 检查正确"的分支,
  • 弹出该存储以恢复您的本地更改.

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

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?

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

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.

我自己从未使用过 SourceTree,但我可以想象,隐藏/检出/弹出是如何涉及大量乏味的鼠标点击.显然,虽然,SourceTree引入了一种名为自定义操作" 允许您定义自己的命令,包括 Git 命令.你可能想看看它...

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天全站免登陆