Quantcast
Channel: Hacking Corner
Viewing all articles
Browse latest Browse all 20

git tips/tricks

$
0
0

I have to admit the more I use git the more I love it. Here are some random tips of commands I have found useful.

===========

-p is your friend

$ git add -p

Hand-pick what changes to add to the next commit.

$ git reset -p

The same as before, but in reverse. Eg. remove some changes from the index.

$ git checkout -p

Choose what changes to discard from the working tree. Be careful with this, you are actually throwing changes completely away.

$ git reset --soft HEAD^
$ git reset -p
$ git diff --cached # see what is going to be in the commit$ git commit -c ORIG_HEAD

Throw some changes away from previous commit. Useful after you've applied a patch from someone, and want to remove some of the changes.

Misc

$ git commit -v

Show a diff of the changes about to be committed. Useful for remembering what to write in the commit message.

$ git rebase -i HEAD~3

Interactively modify latest three commits.

$ git stash save "feature x"$ git stash list
$ git stash pop

Save all changes for later use, and return to a clean tree.

$ git push <repository> :branch

Delete a remote branch.

$ git checkout otherbranch -- file
$ git reset HEAD -- file

Check out a directory from another branch.

\$ git diff --color-words

See what has been changed, but color only words if whole lines have not changed.


Viewing all articles
Browse latest Browse all 20

Trending Articles