Git-暂时保存当前工作 [英] Git - temporarily save current work

查看:118
本文介绍了Git-暂时保存当前工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在master分支上添加功能.更改了几个文件后,我意识到我需要检查输出而不进行任何更改.

I'm adding a feature on master branch. After changing several files, I realize that I need to check the output without my changes.

我能想到的方式是:

  1. 提交当前更改
  2. 签出并切换到新分支
  3. 在新分支中:git reset --hard HEAD^,以便回到原始代码.
  4. 尝试代码,完成后,切换回master分支并删除此新分支.
  1. Commit current changes
  2. Check out and switch to a new branch
  3. In the new branch: git reset --hard HEAD^ so that I get back to the original code.
  4. Try the code and when I'm done, switch back to master branch and delete this new branch.

有更好的方法吗?

我可以保存当前更改的快照并在准备就绪后回来吗?

Can I save a snapshot of current changes and come back later when I am ready?

推荐答案

您可以简单地使用git stash,它将存储您对本地工作树的更改.然后做你的事情,完成后,按git stash pop找回事情.有关隐藏的信息,请参见文档.

You can simply use git stash, which will store away your change to the local working tree. Then do your things, and when you're done, git stash pop to get things back. See the documentation about stashing.

这篇关于Git-暂时保存当前工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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