如何执行 TFS 等效的“撤消挂起的更改”
如何对一个或多个文件执行 Git 中 TFS“撤消挂起的更改”的等效操作?
这基本上意味着执行以下步骤:
- 撤消磁盘上的更改
- 重置 Git 发现的任何
- 更改 从 Git 获取文件的最新更改
如果您了解执行此操作的命令中的差异(如果有),那就太好了(1) 只是在磁盘上更改了它,没有添加它,而且当您(2) 完成了添加命令时,还有一个奖励,( 3) 即使您已经提交了更改。
How do I perform the equivalent of the TFS 'Undo pending changes' in Git, on one or multiple files?
That basically means to do these steps:
- Undo changes on disk
- Resetting any changes Git has discovered
- Getting the latest changes on the file from Git
It would be good to know the differences (if there are any) in commands for doing this if you've (1) just changed it on disk, without adding it, but also when you've (2) done the add-command and for a bonus, (3) even when you have commit the change.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
对于 1 和 2,您需要做的就是:
这将丢弃所有更改。如果您使用
重置
,请务必小心。阅读如何通过重置和结帐操作索引以及硬、软和混合选项的排列。 progit 书详细解释了这一点: http://progit.org/2011/07/11 /reset.html对于 3,
但最好在此之前发出
git stash -u
- 以防万一您有待处理的更改。这会将当前分支重置为当前提交的父分支。在线查找“tree-ish”。引用后的 ^ 和 ~N 将允许您指向该引用历史记录中的任何可到达点。为了了解 git 中如何跟踪历史记录,“Git for Computer Scientifics”很好地解释了有向无环图:http://eagain.net/articles/git-for-computer-scientists/
要从当前提交的状态获取单个文件(即丢弃更改),您可以使用 checkout
如果您发出最后的重置命令上面有错误,你没有遇到麻烦。 Git 会跟踪分支在引用日志中指向的位置。
将列出您的历史记录。您可以在该输出中看到如何引用每个分支,因此:
将分支重置到之前 1 次更改的位置。
添加,如果你想擦除忽略的文件和未跟踪的文件,你可以用这个擦除:
For 1 and 2, all you need to do is:
this will throw away any changes. Be careful if you use
reset
. Read up on manipulating the index and the permutations of the hard, soft and mixed options with the reset and checkout. The progit book explains this in detail: http://progit.org/2011/07/11/reset.htmlFor 3,
but would be better to issue a
git stash -u
before this - just in case you have pending changes.This will reset the current branch to the parent of the current commit. Look up "tree-ish" online. ^ and ~N after a reference will allow you to point to any reachable points in the history of that reference. To understand how history is tracked in git, "Git for computer scientists" explains the Directed Acyclic Graph well: http://eagain.net/articles/git-for-computer-scientists/
To get individual files from the state of the current commit (ie, throw away changes), you can use checkout
If you issued the last reset command above in error, you're not in trouble. Git keeps track of where the branches used to point in the reflog.
will list you the history. You can see in that output how to reference each, so:
will reset the branch to where it used to be 1 change before.
To add, if you want to wipe ignored files and untracked files, you can wipe with this:
此命令将撤消本地更改并将其恢复到存储库中的当前版本:
您可以通过发出以下命令恢复到最后一次有效提交:
如果您只想恢复一个文件,请改用 git checkout :
This command will undo local changes and restore them to the current versions in the repository:
You can revert to your last valid commit by issuing:
If you just want to restore just one file, use git checkout instead:
git checkout [path]
或(整个存储库)git reset --hard HEAD
git reset [path]
后跟git checkout [ path]
git reset --hard [commit]
用于恢复[commit]
处存储库的状态,该状态必须是 树型git checkout [path]
or (entire repo)git reset --hard HEAD
git reset [path]
followed bygit checkout [path]
git reset --hard [commit]
to restore the state of the repo at[commit]
, which must be a tree-ish我与 Eclipse 中 Git 中的
TFS undo
等效,只需右键单击该文件并选择替换为
->HEAD Revision
(或您想要的任何版本)。My equivalent to
TFS undo
in Git with Eclipse is to simply right-click the file and selectReplace with
->HEAD Revision
(or whatever version you'd like).