git 如何丢弃 SourceTree 中未提交的更改?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20234523/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to discard uncommitted changes in SourceTree?
提问by goldfrapp04
I'm new to the Git environment, and I'm using BitBucket with SourceTree on Mac. All I want to do now is to discard the changes since last commit. How should I do this? I haven't found anything like "discard changes", and directly pulling from the last commit doesn't seem to work. Solutions done with either the GUI or command line will be good. Thank you.
我是 Git 环境的新手,我在 Mac 上使用 BitBucket 和 SourceTree。我现在要做的就是放弃自上次提交以来的更改。我该怎么做?我还没有发现像“放弃更改”这样的东西,并且直接从上次提交中提取似乎不起作用。使用 GUI 或命令行完成的解决方案会很好。谢谢你。
采纳答案by Max
I like to use
我喜欢用
git stash
This stores all uncommitted changes in the stash. If you want to discard these changes later just git stash drop
(or git stash pop
to restore them).
这将所有未提交的更改存储在stash 中。如果您想稍后放弃这些更改git stash drop
(或git stash pop
恢复它们)。
Though this is technically not the "proper" way to discard changes (as other answers and comments have pointed out).
尽管这在技术上不是放弃更改的“正确”方式(正如其他答案和评论所指出的那样)。
SourceTree: On the top bar click on icon 'Stash', type its name and create. Then in left vertical menu you can "show" all Stash and delete in right-click menu. There is probably no other way in ST to discard all files at once.
SourceTree:在顶部栏上单击图标“Stash”,输入其名称并创建。然后在左侧垂直菜单中,您可以“显示”所有 Stash 并在右键菜单中删除。ST 中可能没有其他方法可以一次性丢弃所有文件。
回答by Roberto
On SourceTreefor Mac, right click the files you want to discard (in the Files in the working treelist), and choose Reset.
在SourceTreefor Mac 上,右键单击要丢弃的文件(在工作树列表中的文件中),然后选择Reset。
On SourceTreefor Windows, right click the files you want to discard (in the Working Copy Changeslist), and choose Discard.
在SourceTreefor Windows 上,右键单击要丢弃的文件(在Working Copy Changes列表中),然后选择Discard。
On git, you'd simply do:
在git 上,您只需执行以下操作:
git reset --hard
to discard changes made to versioned files;
git reset --hard
放弃对版本化文件所做的更改;
git clean -xdf
to erase new (untracked) files, including ignored ones (the x
option). d
is to also remove untracked directories and f
to force.
git clean -xdf
擦除新的(未跟踪的)文件,包括被忽略的文件(x
选项)。d
还要删除未跟踪的目录并f
强制执行。
回答by NYC Tech Engineer
On the unstaged file, click on the three dots on the right side. Once you click it, a popover menu will appear where you can then Discard file
.
在未暂存的文件上,单击右侧的三个点。单击它后,将出现一个弹出菜单,您可以在那里找到Discard file
。
回答by Mohammad AbuShady
Ok I just noticed that my question was already answered in the question title.
好的,我只是注意到我的问题已经在问题标题中得到了回答。
To unstage files use
要取消暂存文件,请使用
git reset HEAD /file/name
And to undo the changes to a file
并撤消对文件的更改
git checkout -- /file/name
If you have a batch of files inside a folder you can undo the whole folder
如果文件夹中有一批文件,则可以撤消整个文件夹
git checkout -- /folder/name
Note that all these commands are already displayed when you git status
请注意,所有这些命令都已显示 git status
Here I created a dummy repo and listed all 3 possibilities
在这里,我创建了一个虚拟仓库并列出了所有 3 种可能性
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: test
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: test2
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# test3
回答by giuse
From sourcetree gui click on working directoy, right-click the file(s) that you want to discard, then click on Discard
从 sourcetree gui 单击工作目录,右键单击要丢弃的文件,然后单击丢弃
回答by Frostmourne
Do as follow,
做如下,
- Click on
commit
- Select all by pressing
CMD+A
that you want todelete or discard
Right click
on the selected uncommitted files that you want to delete- Select
Remove
from the drop-down list
- 点击
commit
- 按下
CMD+A
你想要的全选delete or discard
Right click
在要删除的选定未提交文件上- 选择
Remove
从下拉列表
回答by ItaiRoded
Ok so in Windows sourcetree that is simple, on macOS I looked as well for a while..
好吧,在 Windows 源树中,这很简单,在 macOS 上我也看了一会儿。
Click Command + Shift + R while in source tree a hidden popup will be shown that will let you discard individual files OR ALL! Why is this hidden? We will never know.. but it works]1
单击 Command + Shift + R,而在源树中将显示一个隐藏的弹出窗口,让您丢弃单个文件或全部!为什么这是隐藏的?我们永远不会知道..但它有效] 1