git 临时存储_如何使用Git存储作为临时存储

git 临时存储

Let’s say you’re coding on your development branch. And you get a notice that there’s a bug in the production branch.

假设您正在开发分支上进行编码。 您会注意到生产分支中存在错误。

You want to check for the bug, but you don’t want to lose the work you’ve created on the development branch. You also don’t want to commit what you’ve written because it’s not done yet.

您想检查该错误,但又不想丢失在Development分支上创建的工作。 您也不想提交所写的内容,因为尚未完成。

What do you do? You can’t commit and you can’t switch branches. If you switch branches, things that aren’t committed will flow over to the branch you switched to.

你是做什么? 您不能提交,也不能切换分支。 如果切换分支,则未提交的内容将流到切换到的分支。

What you want to do is save the changes somewhere temporary while you switch over to another branch. A Git stash is that temporary storage.

您要做的是在切换到另一个分支时将更改临时保存在某个地方。 Git存储是该临时存储。

与Git Fork一起使用隐藏 (Using a Stash with Git Fork)

To use a stash, you need to start with some uncommitted code. For this lesson, we’re going to use the following piece of code as the uncommitted changes:

要使用存储,您需要从一些未提交的代码开始。 在本课程中,我们将使用以下代码作为未提交的更改:

<!-- Some uncommitted code in index.html -->
<main>  <p> A new paragraph</p></main>

To stash this code, you can click on the stash button.

要隐藏此代码,可以单击“隐藏”按钮。

Once you click on the stash button, Fork will ask you to leave a message. This message indicates what the stash is about.

单击存储按钮后,Fork将要求您留言。 此消息指示隐藏的内容。

Since stashes are temporary, you can use whatever name you want. We’re going to call it “Temp storage”.

由于隐藏是临时的,因此您可以使用所需的任何名称。 我们将其称为“临时存储”。

Once you create a new stash, you’ll find it in the Stashes section on the sidebar.

一旦创建了新的存储,您将在侧栏的“存储”部分中找到它。

Note: You won’t be able to see the changes in this stash, but that’s not a problem because you won’t have to. What you want to do is switch your branch, finish what you need to do and switch back.

注意:您将无法看到此存储中的更改,但这不是问题,因为您不必这样做。 您要做的是切换分支,完成所需的操作然后再切换回去。

In this case, we’re going to check out to the master branch. When you do so, notice you don’t see the uncommitted code we wrote above in both the master and develop branches.

在这种情况下,我们将签出到master分支。 这样做时,请注意,您在masterdevelop分支中都看不到我们上面编写的未提交代码。

应用隐藏的更改 (Applying stashed changes)

You can go back to the branch you were at, then right-click on your stash and select Apply stash.

您可以返回到您所在的分支,然后右键单击存储,然后选择“应用存储”。

Fork will ask you whether to delete the stash when you do so. I usually delete the stash because I don’t want to keep more than one stash at one time.

叉子会在您这样做时询问您是否删除存储。 我通常会删除存储,因为我不想一次保留多个存储。

Once you apply the stash, you’ll be able to see the changes you made.

应用存储后,您将能够看到所做的更改。

<!-- You'll see your uncommitted code again! -->
<main>  <p> A new paragraph</p></main>

结语 (Wrapping up)

Stashes are temporary storage spaces where you can store your code. When you’ve stored your code, you can move to other branches to do something else.

暂存区是您可以存储代码的临时存储空间。 存储代码后,可以移至其他分支以执行其他操作。

When you’re done, you can put your code back from the stash.

完成后,您可以将代码从存储中放回去。

With Git Stash, you won’t have to worry about losing any uncommitted changes!

使用Git Stash,您将不必担心丢失任何未提交的更改!

Thanks for reading. Did this article help you in any way? If you did, I hope you consider sharing it. You might help someone out. Thank you!

谢谢阅读。 本文对您有任何帮助吗? 如果这样做, 希望您考虑共享它 。 您可能会帮助某人。 谢谢!

This article was originally posted at zellwk.com.Sign up for my newsletter if you want more articles to help you become a better front-end developer.

本文最初发布于zellwk.com 如果您想要更多文章来帮助您成为更好的前端开发人员,请注册我的新闻通讯

翻译自: https://www.freecodecamp.org/news/how-to-use-git-stash-as-temporary-storage-84a0a1e37a43/

git 临时存储

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值