Git:替代藏匿处 [英] Git: alternative for stash

查看:73
本文介绍了Git:替代藏匿处的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为项目使用 Git扩展.我很喜欢.有一个问题一直困扰着我,我很确定Git Extensions中有一个窍门.这是场景:

I'm using Git Extensions for my projects. I really like it. There is an issue that keeps bugging me and I'm pretty sure there is a trick in Git Extensions for it. Here is the scenario:

  • 我从master分支创建了3个分支,分别是 A B C .
  • 开始在分支 A 中工作,进行了一些更改
  • 切换到分支 B ,我仍然看到在 A 中所做的更改,因为它们尚未提交
    • 我不想在 A 中提交更改,因为我尚未完成,并且我不希望此提交出现在提交历史记录中
    • 我不想在 A 中存储更改,因为如果我在 B 中进行更改并切换到 C ,则必须存储 B 中的更改也==> A 中的更改已消失:被新存储区覆盖.
    • From master branch, I created 3 branches A, B and C.
    • Started working in branch A, did some changes
    • Switched to branch B, I still see changes made in A as they are not committed
      • I don't want to commit changes in A because I'm not done yet and I don't want this commit to appear in commit history
      • I don't want to stash changes in A because if I make changes in B and switch to C, I have to stash changes in B too ==> changes in A are gone: overridden by the new stash.

      我可以在不同的分支中进行很多藏匿吗?
      如果不是,那么 stash 的替代方案是什么?
      commit revert commit 是我唯一的选择吗?

      Can I make many stashes in different branches?
      If not, whats the alternative for stash?
      Is commit and revert commit my only option here?

      推荐答案

      git worktree

      Git工作树于2007年在git repo中的 contrib 文件夹下引入,被称为 new-workdir .

      git worktree

      Git worktree was introduced in 2007 under the contrib folder in git repo and was called new-workdir.

      例如:

      git worktree add <second path>
      

      将在您的计算机上创建另一个文件夹,该文件夹使您可以同时在不同的分支上工作.

      will create another folder on your computer which allow you to work on different branch simultaneously.

      git worktree 将创建2个单独的工作文件夹,同时指向相同的存储库.

      git worktree will create 2 separate working folders separated from each other while pointing to the same repository.

      这将使您可以在新工作树上进行任何实验,而不会对存储库本身产生任何影响.在所附的图像中,您可以看到有 2个单独的工作文件夹,但是它们都使用单个仓库并共享内容.

      This will allow you do to any experimentals on the new worktree without having any effect on the repository itself. In the attached image you can see that there are 2 separate working folder but both of them are using a single repo and share the content.

      以下是有关如何创建新工作树及其结果的示例:

      Here is a sample on how to create new worktree and what is the result of it:

      我可以在不同的分支机构进行很多藏匿吗?

      Can I make many stashes in different branches?

      是的,但是可以避免.您可以将存储区弹出到与原始存储源不同的分支.

      Yes you can but you want to avoid it. You can pop up stash to different branches than the one you originally stahed the sources.

      如果没有,隐藏的替代方法是什么?

      If not, whats the alternative of stash?

      如上所述,请使用工作树

      As explained above - use worktree

      是提交还是还原提交,这是我唯一的选择吗?

      Is commit and revert commit, my only option here?

      再次:如上所述,请使用工作树

      Again: As explained above - use worktree

      这篇关于Git:替代藏匿处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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