Blog

  • Hey Hi,
    In previous blog, we discussed about basic git commands and their usage,
    In this blog, I'll tell you about some special commands in git on particular problems.

    We'll include following points in this blog:
    * Reset - Reset current codebase
    * Checkout - create a new branch or switch to existing branch or switch to specific commit
    * Stash - Stores current usable data to a persistant location other than commits

     

    Reset - Reset current codebase

    * To reset codebase to latest available commmit ( we use this option to discard available useless data modification)
    $ git reset --hard

    * To reset codebase to particular commit
    $ git reset --hard <commit_hash_id>

    * To reset codebase to particular commit on to remote repository:
    $ git reset --hard <commit_hash_id>
    $ git push -u origin <current_branch_name>

     

    Checkout - create a new branch or switch to existing branch or switch to specific commit

    * To create a new branch, use following git command in your local repository:
    $ git checkout -b <branch_name>

    * To switch to existing branch, simply:
    $ git checkout <branch_name>

    * To switch to specific commit
    $ git checkout <commit_hash>

    * To reset specific file from modified changes
    $ git checkout -- <file_path_relative_to_current_repository>

     

    Stash - Stores current usable data to a persistant location other than commits

    To secure available useful but non-committable data before taking pull, to avoid conflict during the pull we use 'git stash'.
    Alternatively, we can also use this when we want to store some changes that are to be commitable after some other required modifications.
    it doesn't affect remote version of repository, it maintains a stash list as a stack.

    * To stash, we use following command:
    $ git stash
    it simply creates an entry in stash list (different then commit list)

    * To view stash list
    $ git stash list

    * To reload most recent stash changes, we use:
    $ git stash pop

    * To reload specific indexed stash change, we use:
    $ git stash pop stash@{index} (it may be 0 to available indexes in list)

    * To clear stash list
    $ git stash clear

    Thanks for reading my blog, your comments will be valuable.

Tags: Git