如何执行TFS等效的'撤消挂起的更改' [英] How to perform the TFS-equivalent of 'Undo pending changes'

查看:316
本文介绍了如何执行TFS等效的'撤消挂起的更改'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Git中执行相当于TFS的'撤消挂起更改',在一个或多个文件上?



这基本上意味着要执行这些步骤: / b>


  • 撤销磁盘上的更改
  • 重置Git发现的任何更改

  • 从Git获取文件的最新更改



最好知道其中的差异(如果有的话)如果您(1)只是在磁盘上更改了它,而没有添加它,那么您也可以执行此命令,但是也可以在(2)完成add-command 和作为奖励,(3)即使您已经提交更改

2,所有你需要做的是:

  git stash -u #same effect git reset --hard,but can be撤消

这会抛弃所有更改。如果使用 reset ,请小心。阅读操作复位和结账的指数和硬,软和混合选项的排列。 progit书详细解释了这一点: http://progit.org/2011/07/11 /reset.html



For 3,

  git reset --hard HEAD ^ 

但是最好发行 git stash -u 在此之前 - 以防万一您有未决的更改。



这会将当前分支重置为当前提交的父级。在网上查找tree-ish。参考后的^和〜N将允许您指向该参考历史记录中的任何可到达的点。为了理解git中的历史记录是如何被跟踪的,计算机科学家的Git很好地解释了有向无环图: http://eagain.net/articles/git-for-computer-scientists/



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

  git checkout HEAD  - <文件列表> 

如果您错误地发出了上面的最后一个重置命令,那么您没有麻烦。 Git会跟踪分支用于指向reflog的位置。

  git reflog 

会列出您的历史记录。您可以在输出中看到如何引用它们,例如:

  git reset --hard HEAD @ {1} 

会将分支重置为之前的1次更改。



要添加,如果要擦除忽略文件和未跟踪文件,可以使用以下命令擦除:

  git clean -xdf 


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.

解决方案

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

这篇关于如何执行TFS等效的'撤消挂起的更改'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆