Wednesday, January 9, 2013

Git: to discard changes


If the changes in the working directory are not committed, we can run:
  $ git checkout -b BranchToBeDiscarded
  $ git add .
  $ git commit -a -m "commit the changes to an abandoned branch"
  $ git checkout master

The first three commands check in the changes in the working directory to a temporary branch. That makes the working directory clean so that we can use the last command to update the working directory by the HEAD of the master branch.

If you know confidently that the changes are not wanted, you can run:
  $ git checkout -- .
which permanently purge the changes.

If the changes in the working directory are committed, we can run:
  $ git revert <last-commit>

There is also a dangerous way of doing it if you want to remove the last commit completely. You can run:
  $ git reset <the-commit-to-be-the-new-HEAD>
and any commits after that one will gone.

No comments:

 
Get This <