Git tricks

Collection of useful git commands etc.

Revert a pull/merge etc.-up-

  • get a list of recent commits with git log --oneline
  • select the hash (first word on each line) of the one you want to revert
  • git revert -m 1 <selected_hash>

Locally merge a pull request-up-

See this stackexchange Q&A.

After cloning the repo, choose one of these options:

  • download the PR as a .diff by appending .diff to the URL, e.g.:
    for PR 123, then patch manually.
  • issue git pull origin pull/123/head.

Remove untracked files-up-

Dry run:

git clean -d -n


git clean -d -f