Saturday, February 16, 2013

Useful Git commands

In this post, I want to show some very useful Git commands for everyday use.

Show diff of single commit

git diff ^<commit>

git diff ^HEAD # Show diff of last commit

Generate git patch from single commit

git format-patch -1 <commit>

git format-patch -1 HEAD # Generate patch from last commit

Show history of a file

git log -p -- path/to/file

Commit as a different author

git commit --author <e-mail>

Edit last commit (not yet pushed)

git commit --amend

Remove last commit (not yet pushed)

Very useful for cases when someone pushed and you commited and didn't pull.
git reset --soft HEAD~1 # HEAD~2 for 2 commits, etc

Stash only some files

To stash files not staged for commit, as seen in picture:
git stash --keep-index

Delete untracked files

git clean -f

3 comments:

  1. This is one of the vital info I have read. Am glad to read your article. Why are my Texts Going Green to Another iphone

    ReplyDelete
  2. This amazing content is exactly what I was looking for, thanks for sharing keep up the good work. Also, Check condolence messages

    ReplyDelete
  3. 토토365프로 Hi to every one, it's in fact a nice for me to pay a quick
    visit this website, it consists of important Information.


    ReplyDelete