Posted on

GIT advice

    1. Show log
      git log

      1. --author="" – print commits by pointed user
      2. --name-only – only file name
      3. --oneline – commits comments in one line
      4. --graph – commits tree
      5. --reverse – old commits before new commits
      6. --after – commits after pointed date
      7. --before – commits before pointed date

  1. Show the latest edits
    git log -p <filename>
  2. Show edits in pointed lines of file
    git blame filename
    git log -L 1,1:filename
  3. Show no merged commits
    git log --no-merges master..
    git show --no-merges master..
    git log -p --no-merges master..
  4. Extract file from a branch
    git show branch:file
  5. Rebase
    git rebase -i <commithash>
    git pull -rebase
  6. Local merge
    git merge --no-ff branchname
  7. Fix latest commit
    git commit --amend
    git push -f (DON’T DO IT)
  8. Status
    git status -s

    1. Reset
      git reset --hard <hash> – all commits after will disappear
      git reset <hash> – all commits after will be “not staged for commit”
      git reet --soft <hash> – all commits after will be “staged for commit”
    2. Extract files
      git checkout filename
      git checkout branchname filename
      git checkout commithash filename
  9. Revert
    git revert -n
  10. Diff
    git config --global diff.tool <name>
    git config --global merge.tool <name>
    git difftool filename
    git difftool -d
  11. Ignore space
    git <some command> -w
  12. Add a part of file
    git add -p
  13. Delete old branches
    git branch -a --merged
    git fetch -p
  14. Stash
    git stash --keep-index
    git stash -p
    git stash pop
    git stash list
  15. Bisect
    git bisect
    git bisect start
    git bisect good <hash>
    git bisect bad <hash>
    git bisect good
    git bisect bad
    git bisect reset
    git bisect log
Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.