如何在 Git Gui 中放弃对文件的更改?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20242880/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 17:23:02  来源:igfitidea点击:

How do I discard changes for a file in Git Gui?

gitgit-gui

提问by Dirk

Often when using Git Gui I would like to reset/checkout a single file or just dismiss a hunk.

通常在使用 Git Gui 时,我想重置/检出单个文件或只是关闭一个大块头。

Is there a way to do this easily in Git Gui? If not, is there any particular reason that this feature is not available in Git Gui?

有没有办法在 Git Gui 中轻松做到这一点?如果没有,是否有任何特殊原因在 Git Gui 中不提供此功能?

采纳答案by ThanksForAllTheFish

I know this way:

我知道这样:

  1. The changes must be unstaged
  2. Go to Tools-> Add
  3. Choose whatever name you'd like for your command, then in Commandwrite
    git checkout $REVISION -- $FILENAME
  4. Select (left-click) the file you want to checkout, without staging
  5. Choose from Toolsthe command you just created
  1. 更改必须取消暂存
  2. 转到工具->添加
  3. 为您的命令选择您想要的任何名称,然后在命令中写入
    git checkout $REVISION -- $FILENAME
  4. 选择(左键单击)要签出的文件,不暂存
  5. 工具中选择您刚刚创建的命令

The chosen file will be checked out to HEADrevision

所选文件将被检出以进行HEAD修订

回答by lienok

I had a same problem. Just found it out: CTRL+J or Commit - Revert Changes

我有同样的问题。刚刚发现:CTRL+J 或 Commit - Revert Changes

回答by Siddarth Kanted

  1. Select the file from the file list in the left sidebar.
  2. In the Menu bar, under Commit, Click "Revert Changes" in the dropdown list.
  1. 从左侧边栏中的文件列表中选择文件。
  2. 在菜单栏中的“提交”下,单击下拉列表中的“还原更改”。

Alternatively, you can use the keyboard shortcut Ctrl+Jto trigger the same action on Windows.

或者,您可以使用键盘快捷键Ctrl+J在 Windows 上触发相同的操作。

enter image description here

在此处输入图片说明

回答by Rosario Palazzo

Select the file you want to reset from the "Unstaged changes window". Then click Menù - Branch - Reset -

从“Unstaged changes 窗口”中选择要重置的文件。然后点击菜单-分支-重置-

You will have the file before the changes you did as the last commit.

您将在最后一次提交所做的更改之前拥有该文件。

回答by VonC

Revert Change will work with untracked filestoo, with Git 2.25 and git-gui.

还原更改也适用于未跟踪的文件,使用 Git 2.25 和git-gui.

See commit 0d2116c(04 Jan 2020), commit 23cbe42(19 Dec 2019), commit 1e1ccbf(06 Dec 2019), commit d32e065(11 Dec 2019), and commit 2763530(05 Dec 2019) by Pratyush Yadav (prati0100).
See commit 786f4d2(30 Dec 2019) by Zoli Szabó (zoliszabo).
See commit 39acfa3(07 Dec 2019) by Kazuhiro Kato (kkato233).
See commit fa38ab6, commit d9c6469, commit 29a9366(01 Dec 2019) by Jonathan Gilbert (jpg0).
(Merged by Junio C Hamano -- gitster--in commit fe47c9c, 08 Jan 2020)

提交0d2116c(2020年1月4日),提交23cbe42(2019年12月19日),提交1e1ccbf(2019年12月6日),提交d32e065(2019年12月11日),并提交2763530(2019年12月5日)由Pratyush亚达夫(prati0100
请参阅Zoli Szabó ( )提交的 786f4d2(2019 年 12 月 30 日。 请参阅Kazuhiro Kato ( ) 的commit 39acfa3(2019 年 12 月 7 日。 请参阅Jonathan Gilbert ( ) 的commit fa38ab6commit d9c6469commit 29a9366(01 Dec 2019 )zoliszabo
kkato233
jpg0
(由Junio C gitsterHamano合并-- --fe47c9c 提交中,2020 年 1 月 8 日)

git-gui: revert untracked files by deleting them

Signed-off-by: Jonathan Gilbert
Signed-off-by: Pratyush Yadav

Update the revert_helperproc to check for untracked files as well as changes, and then handle changes to be reverted and untracked files with independent blocks of code.

Prompt the user independently for untracked files, since the underlying action is fundamentally different (rm -f).
If after deleting untracked files, the directory containing them becomes empty, then remove the directory as well.

Migrate unlocking of the index out of _close_updateindexto a responsibility of the caller, to permit paths that don't directly unlock the index, and refactor the error handling added in d4e890e5so that callers can make flow control decisions in the event of errors.
Update Tcl/Tk dependency from 8.4 to 8.6 in git gui.sh.

A new proc delete_filestakes care of actually deleting the files in batches, using the Tcler's Wiki recommended approach for keeping the UI responsive.

Since the checkout_indexand delete_filescalls are both asynchronous and could potentially complete in any order, a "chord" is used to coordinate unlocking the index and returning the UI to a usable state only after both operations are complete. The SimpleChordclass, based on TclOO (Tcl/Tk 8.6), is added in this commit.

git-gui:通过删除它们来恢复未跟踪的文件

签字人:Jonathan Gilbert
签字人:Pratyush Yadav

更新revert_helperproc 以检查未跟踪的文件和更改,然后使用独立的代码块处理要还原的更改和未跟踪的文件。

独立提示用户未跟踪的文件,因为底层操作根本不同 ( rm -f)。
如果删除未跟踪文件后,包含它们的目录变为空,则也删除该目录。

将索引的解锁迁移_close_updateindex到调用者的职责之外,以允许不直接解锁索引的路径,并重构d4e890e5 中添加的错误处理,以便调用者可以在发生错误时做出流量控制决策。
git gui.sh 中的Tcl/Tk 依赖从 8.4 更新到 8.6 。

一个新的 procdelete_files负责实际批量删除文件,使用 Tcler 的 Wiki 推荐的方法来保持 UI 响应。

由于checkout_indexdelete_files调用都是异步的并且可能以任何顺序完成,因此“和弦”用于协调解锁索引和仅在两个操作完成后才将 UI 返回到可用状态。SimpleChord在此提交中添加了基于 TclOO (Tcl/Tk 8.6)的类。