Một vài câu lệnh git (nâng cao)
git cat-file -p <commit>
. VD:git cat-file -p master
. Kết qủa
tree 78ff5631102bf0a3ffa324aba689eb8f747b3524
parent af17132094f118b6b126b11ca2422fb2f17e65a4
author Tran Sang <info@transang.me> 1545708057 +0900
committer Tran Sang <info@transang.me> 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 commitsgit --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 beforenow
git log --oneline --decorate
: git log with decoratorgit --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 childrengit branch --contains <commit>
: find branches that contains a specific commitgit merge-base <commit 1> <commit 2>
: find the nearest ancestors of 2 commitsgit checkout --orphan <new-branch> <commit>
: checkout<commit>
into<new-branch>
without coping commit historygit rebase --onto branch-1 commit-base commit-now
: apply all changes oncommit-now
compared withcommit-base
, intobranch-1
. All commits betweencommit-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 fromcommit-now
if conflict happens. When-Xtheirs
is replaced by-Xours
, always apply changes frombranch-1
if conflict happens.git verify-pack -v .git/objects/pack/pack-<hash>.idx
: verify internal pack objectls .git/objects
: list all commits and their content.pack
andinfo
contain packed commits viagit 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)