Giter VIP home page Giter VIP logo

git_magic's Introduction

git_magic

This file contains git commands which I have found useful for rescuing me from tricky situations and saving hours of work

  1. Restore local branch to same as remote, reverting all local changes and commits

    Context: You have messed up local branch and not sure where you are now. In such situation I have found it best to go back to sanity and restore the remote branch dis-regarding all local commited and un-commited changes

    Template - git reset --hard origin/<branch_name>

    Example - git reset --hard origin/master

  2. Quick check what changes a commit contains

    Context: You want to check the history of a branch and the changes that went in a particular commit bit you dont have only the CLI based tools

    Template - i) git log //This will show all the recent commits

    ii) git show // This will show a diff of the files in the commit

  3. Create a branch from a given tag

    Context - Your main branch is tagged with release_id and you want to give a patch on a given release

    Template git checkout -b <new_branch_name> tags/<tag_name>

  4. Get a patch for a commit to apply in another branch.

    Context - You made committed changes in a shared branch. There are other changes on top of it. You want to cherry pick your commit and have it exported as a patch file so that you can mail it to your friend and apply it in his branch.

    git log // Fetch the sha of the commit from history

    git format-patch -1 //Will create a pathc file in the current directory

    git am < file.patch

  5. Rename a local branch (while you are on the branch)

    git branch -m "<new_branch_name>"

  6. Undo the most recent local comit

    git reset HEAD~

  7. Undo a git reset

    git reset 'HEAD@{1}'

  8. Delete a local branch

    git branch -d

  9. Delete a remote branch

    git push -d origin

git_magic's People

Contributors

sashutosh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.