Vault7: CIA Hacking Tools Revealed
Navigation: » Latest version
Owner: User #524297
Git Tips & Tricks
Add your best Git tricks here!
Share the love! |
---|
The "The Git URLUniform Resource Locator is too long" Trick
# add the following to your ~/.ssh/config
Host stash
User git
Hostname stash.devlan.net
Port 7999
IdentityFile ~/.ssh/<your SSHSecure Shell private key pair>
$ git clone ssh://git@stash.devlan.net:7999/proj/projectname.git
# .... now becomes ....
$ git clone stash:/proj/projectname.git
The "I forgot something in my last commit" Trick
# first: stage the changes you want incorporated in the previous commit
# use -C to reuse the previous commit message in the HEAD
$ git commit --amend -C HEAD
# or use -m to make a new message
$ git commit --amend -m 'add some stuff and the other stuff i forgot before'
The "Oh crap I didn't mean to commit yet" Trick
# undo last commit and bring changes back into staging (i.e. reset to the commit one before HEAD)
$ git reset --soft HEAD^
The "That commit sucked! Start over!" Trick
# undo last commit and destroy those awful changes you made (i.e. reset to the commit one before HEAD)
$ git reset --hard HEAD^
The "Oh no I should have been working in a branch" Trick
# takes staged changes and 'stashes' them for later, and reverts to HEAD.
$ git stash
# creates new branch and switches to it, then takes the stashed changes and stages them in the new branch. fancy!
$ git stash branch new-branch-name
The "OK, what commit broke it!?
# Made lots of local commits and haven't run any tests...
$ [unittest runner of choice]
# Failures... now unclear where it was broken.
# git bisect to rescue.
$ git bisect start # to initiate a bisect
$ git bisect bad # to tell bisect that the current rev is the first spot you know was broken.
$ git bisect good <some tag or rev that you knew was working>
$ git bisect run [unittest runner of choice]
# Some runs.
# BLAMO -- git shows you the commit that broke
$ git bisect reset #to exit and put code back to state before git bisect start
# Fix code. Run tests. Commit working code. Make the world a better place.