How to perform the TFS-equivalent of 'Undo pending changes'

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:

  • How do I ask git, which commits are not on a branch?
  • Git error: src refspec master does not match any error: failed to push some refs
  • Why won't this display the dynamic cgi?
  • git unable to rm --cached files
  • Completely remove files from Git repo and remote on GitHub
  • couting number of files in git repository
    • 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.

  • In what cases could `git pull` be harmful?
  • Rewrite history git filter-branch create / split into submodules / subprojects
  • Git: can we compare two staged-version of the same files?
  • Where is git-blame in SourceTree
  • How to export a function, from tmux.conf
  • How does one divide changes among multiple branches in git?
  • 4 Solutions collect form web for “How to perform the TFS-equivalent of 'Undo pending changes'”

    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:

    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:

    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

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

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

    Git Baby is a git and github fan, let's start git clone.