• git cat-file -p <commit>. VD: git cat-file -p master. Kết qủa
tree 78ff5631102bf0a3ffa324aba689eb8f747b3524
parent af17132094f118b6b126b11ca2422fb2f17e65a4
author Tran Sang <tranvansangk41@gmail.com> 1545708057 +0900
committer Tran Sang <tranvansangk41@gmail.com> 1545708057 +0900

remove UserAppContainer.js. rebase bug?

78ff5631102bf0a3ffa324aba689eb8f747b3524: commit hash

af17132094f118b6b126b11ca2422fb2f17e65a4: parent commit hash

còn lại: nội dung của commit

Lệnh này dùng để in ra thông tin của bất kì object nào trong git repo.

  • git fsck --no-reflogs: list all dangling commits
  • git --no-pager log --format='%H %P' --all: list all logs with format, good for searching through all git history. Check all specifiers here
#!/bin/bash -e
commit=$@
while true; do
  found=false
  for child in $(git log --format='%H %P' --all | grep -F " $commit" | cut -f1 -d' '); do
    commit=$child
    git --no-pager show -s --format='%H %an %ci' $commit
    found=true
    break
  done
  if [[ $found = false ]]; then
    break
  fi
done

Iterate through first child of a given commit. Used to debug to figure out why a commit is not orphaned

  • git gc --prune=now --aggressive: (garbage collector) prune orphaned commit before now
  • git log --oneline --decorate: git log with decorator
  • git --no-pager log: git log without prompt
  • : 1545717444:0;COMMIT=<commit hash>; git rev-list --all --not $COMMIT^@ --children | grep "^$COMMIT": another command to find a commit's children
  • git branch --contains <commit>: find branches that contains a specific commit
  • git merge-base <commit 1> <commit 2>: find the nearest ancestors of 2 commits
  • git checkout --orphan <new-branch> <commit>: checkout <commit> into <new-branch> without coping commit history
  • git rebase --onto branch-1 commit-base commit-now: apply all changes on commit-now compared with commit-base, into branch-1. All commits between commit-base...commit-now will be dangled (if they are not parent of any named branched)
  • git rebase -Xtheirs --onto branch-1 commit-base commit-now: always apply changes from commit-now if conflict happens. When -Xtheirs is replaced by -Xours, always apply changes from branch-1 if conflict happens.
  • git verify-pack -v .git/objects/pack/pack-<hash>.idx: verify internal pack object
  • ls .git/objects: list all commits and their content. pack and info contain packed commits via git repack --max-pack-size=10M (automatically executed frequently by git)
  • git -c gc.reflogExpire=0 -c gc.reflogExpireUnreachable=0 -c gc.rerereresolved=0 -c gc.rerereunresolved=0 -c gc.pruneExpire=now gc "$@": clean git (deeper)

Source