简体   繁体   English

隐藏使用 atlassian sourcetree 所做的更改

[英]Stash the changes made with atlassian sourcetree

I have a lot of files changed in my project.我的项目中更改了很多文件。 I want to stash 2 files but i'm a bit afraid to make a mistake since i never did this.我想存储 2 个文件,但我有点害怕犯错,因为我从来没有这样做过。

If i would stash now, will it only stash the 2 staged files?如果我现在要藏起来,它会只藏 2 个暂存文件吗?在此处输入图片说明

And if I don't mark the "Keep staged changes", will it then revert to how it was before?如果我不标记“保持分阶段更改”,它会恢复到以前的状态吗? This might sound stupid, but better save then sorry.这听起来可能很愚蠢,但最好保存然后抱歉。

This applies to Git in general, not just with SourceTree.这通常适用于 Git,而不仅仅是 SourceTree。 When you stash changes, the items that will be stashed are the changes to tracked files in your working copy and in the staging area.当您存储更改时,将被存储的项目是对工作副本和暂存区域中跟踪文件的更改。 Those changes will be saved in the stash , and reverted in the working copy and index.这些更改将保存在 stash 中,并在工作副本和索引中恢复。

When you choose to keep changes in the index/staging area, those changes will still be stashed, but Git won't also revert them in the staging area.当您选择在索引/暂存区中保留更改时,这些更改仍将被隐藏,但 Git 也不会在暂存区中恢复它们。 This is useful if, for example, you make several unrelated changes, and you want to run tests only some of those changes, without having the unrelated ones affect the test.例如,如果您进行了几个不相关的更改,并且您只想运行其中一些更改的测试,而不会使不相关的更改影响测试,那么这很有用。

Stashing is safe .藏匿是安全的 If you want to get your stashed changes back, you just pop them back out of the stash.如果您想取回隐藏的更改,只需将它们从存储中弹出即可。

However, untracked files aren't normally stashed.但是,通常不会隐藏未跟踪的文件 If you want to also stash those files, you need to pass an additional option to git stash on the command line (SourceTree for Windows doesn't currently have such an option. I don't know if the same is true for the Mac version):如果您还想存储这些文件,则需要在命令行上向git stash传递一个附加选项(Windows 的 SourceTree 目前没有这样的选项。我不知道 Mac 版本是否也是如此):

git stash save --include-untracked
# Or shorter
git stash save -u

See Also也可以看看

Yes, but stashing in this case would mean two scenarios -是的,但在这种情况下藏匿意味着两种情况——

  1. Checking the Keep staged changes: staged files would still be in your staging area, but all your modified unsaved files will be stashed.检查保留暂存更改:暂存文件仍将在您的暂存区域中,但所有修改后的未保存文件将被隐藏。

  2. Without checking the staged changes: all your files will be stashed.不检查分阶段更改:您的所有文件都将被隐藏。

I'm also looking for a way to stash only a few items from my working copy and I stumbled upon this question.我也在寻找一种方法来从我的工作副本中只存储一些项目,我偶然发现了这个问题。 I found a workaround that was mentioned in the official Atlassian forums .我找到了官方 Atlassian 论坛中提到的解决方法。 I tried it using SourceTree version 3.3.8 for Windows and it works for me.我使用适用于 Windows 的 SourceTree 3.3.8 版进行了尝试,它对我有用。

To stash select files:要隐藏选择的文件:

  • Stage the files you want to stash暂存要隐藏的文件

  • Then stash all files, but making sure that 'Keep staged changes' is checked然后隐藏所有文件,但确保选中“保留暂存更改”

  • Now you only have the files you want to stash in your current working copy现在你只有你想要隐藏在当前工作副本中的文件

  • Stash all files, with 'Keep staged changes' unchecked隐藏所有文件,取消选中“保留暂存更改”

You can then re-apply the first stash, and discard the files that you wanted to stash.然后您可以重新应用第一个 stash,并丢弃您想要 stash 的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM