Changes between Version 37 and Version 38 of Developer/Git


Ignore:
Timestamp:
Feb 13, 2012, 10:09:06 PM (7 years ago)
Author:
Gedare
Comment:

/* Reverting Changes */

Legend:

Unmodified
Added
Removed
Modified
  • Developer/Git

    v37 v38  
    183183}}}
    184184
    185 To remove commits there are two useful options, reset and revert; revert is cleaner, and is the right way to revert changes that have already been pushed/pulled remotely.
    186 {{{
    187  git reset HEAD-1
    188 }}}
    189 Removes the last 1 (or any other number you put) commit from the current branch. git reset should only be used on local branches that no one else is accessing remotely. This is a very powerful and tricky command; A good description of what it enables to do can be found [http://progit.org/2011/07/11/reset.html here]
    190 {{{
    191  git revert HEAD~1
    192 }}}
    193 Does the same as reset but creates a new commit with the reverted changes instead of modifying the local repository directly.
     185To remove commits there are two useful options, reset and revert. git reset should only be used on local branches that no one else is accessing remotely. git revert is cleaner, and is the right way to revert changes that have already been pushed/pulled remotely.
     186= git reset =
     187
     188git reset is a powerful and tricky command: A good description of what it enables to do can be found [http://progit.org/2011/07/11/reset.html here]. The following are a few useful examples. Note that adding a ~ after HEAD refers to the most recent commit, and you can add a number after the ~ to refer to commits even further back; HEAD by itself refers to the current working directory (changes since last commit).
     189{{{
     190git reset HEAD~
     191}}}
     192Will undo the last commit and unstage those changes. Your working directory will remain the same, therefore a "git status" will yield any changes you made plus the changes made in your last commit. This can be used to fix the last commit. You will need to add the files again.
     193
     194{{{
     195git reset --soft HEAD~
     196}}}
     197Will just undo the last commit. The changes from last commit will still be staged (just as if you finished git adding them).  This can be used to amend the last commit (e.g. I forgot to add a file to the last commit).
     198
     199{{{
     200git reset --hard HEAD~
     201}}}
     202Will revert everything, including the working directory, to the previous commit. This is dangerous and can lead to you losing all your changes.
     203
     204{{{
     205git reset HEAD
     206}}}
     207Will unstage any change. This is used to revert a wrong git add. (e.g. I added a file that shouldn't be there, but I haven't 'committed')
     208
     209{{{
     210git reset --hard HEAD
     211}}}
     212Will revert your working directory to a HEAD state. You will lose any change you made to files after the last commit. This is used when you just want to destroy all changes you made since the last commit.
     213= git revert =
     214
     215git revert does the same as reset but creates a new commit with the reverted changes instead of modifying the local repository directly.
     216{{{
     217 git revert HEAD
     218}}}
     219This will create a new commit which undoes the change in HEAD. You will be given a chance to edit the commit message for the new commit.
    194220= Merging Changes =
    195221