Some Useful Git Commands

As an on-the-way-to-becoming-a-serious developer, I think I had better get familiar with some source code manager software, and that is: Git.

As I learn how to use git, I want to keep track of what I have learned, and keep it down so I can go back and see should I forget it. This is supposed to be a update-if-needed list. So here are some git commands:

  • To make a directory git-aware, i.e. to initialize a git repository:

  • To check status:

  • To add file to staging index:

  • To commit changes:

  • To switch to another branch:

  • To discard changes on file in working directory:

ps: — means not to care about branches, but just files in current branch.

  • To unstage file:

  • To change a file back to one of previous states:

where 8a64b9a6871 is a SHA of previous commit.

  • To view previous commits:

where -n limits how many history commits to show.

  • To reset all files to a previous state:




Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.