如何执行 TFS 等效的“撤消挂起的更改”

发布于 2024-12-13 13:05:09 字数 296 浏览 6 评论 0原文

如何对一个或多个文件执行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

月亮是我掰弯的 2024-12-20 13:05:09

对于 1 和 2,您需要做的就是:

 git stash -u #same effect as git reset --hard, but can be undone

这将丢弃所有更改。如果您使用重置,请务必小心。阅读如何通过重置和结帐操作索引以及硬、软和混合选项的排列。 progit 书详细解释了这一点: http://progit.org/2011/07/11 /reset.html

对于 3,

 git reset --hard HEAD^

但最好在此之前发出 git stash -u - 以防万一您有待处理的更改。

这会将当前分支重置为当前提交的父分支。在线查找“tree-ish”。引用后的 ^ 和 ~N 将允许您指向该引用历史记录中的任何可到达点。为了了解 git 中如何跟踪历史记录,“Git for Computer Scientifics”很好地解释了有向无环图:http://eagain.net/articles/git-for-computer-scientists/

要从当前提交的状态获取单个文件(即丢弃更改),您可以使用 checkout

git checkout HEAD -- <a list of files>

如果您发出最后的重置命令上面有错误,你没有遇到麻烦。 Git 会跟踪分支在引用日志中指向的位置。

git reflog

将列出您的历史记录。您可以在该输出中看到如何引用每个分支,因此:

git reset --hard HEAD@{1}

将分支重置到之前 1 次更改的位置。

添加,如果你想擦除忽略的文件和未跟踪的文件,你可以用这个擦除:

git clean -xdf

For 1 and 2, all you need to do is:

 git stash -u #same effect as git reset --hard, but can be undone

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.html

For 3,

 git reset --hard HEAD^

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

git checkout HEAD -- <a list of files>

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.

git reflog

will list you the history. You can see in that output how to reference each, so:

git reset --hard HEAD@{1}

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 clean -xdf
随风而去 2024-12-20 13:05:09

此命令将撤消本地更改并将其恢复到存储库中的当前版本:

git reset --hard

您可以通过发出以下命令恢复到最后一次有效提交:

git reset --hard HEAD

如果您只想恢复一个文件,请改用 git checkout :

git checkout -- file_name.extension
git checkout HEAD file_name.extension

This command will undo local changes and restore them to the current versions in the repository:

git reset --hard

You can revert to your last valid commit by issuing:

git reset --hard HEAD

If you just want to restore just one file, use git checkout instead:

git checkout -- file_name.extension
git checkout HEAD file_name.extension
子栖 2024-12-20 13:05:09
  1. git checkout [path] 或(整个存储库)git reset --hard HEAD
  2. git reset [path] 后跟 git checkout [ path]
  3. git reset --hard [commit] 用于恢复 [commit] 处存储库的状态,该状态必须是 树型
  1. git checkout [path] or (entire repo) git reset --hard HEAD
  2. git reset [path] followed by git checkout [path]
  3. git reset --hard [commit] to restore the state of the repo at [commit], which must be a tree-ish
梦在深巷 2024-12-20 13:05:09

我与 Eclipse 中 Git 中的 TFS undo 等效,只需右键单击该文件并选择 替换为 -> HEAD Revision(或您想要的任何版本)。

My equivalent to TFS undo in Git with Eclipse is to simply right-click the file and select Replace with -> HEAD Revision (or whatever version you'd like).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文