Git 初 - 指令操作教
git log --pretty=oneline # 秀 log 的方式git log --pretty=short # 秀 log 的方式git log --pretty=format:'%h was %an, %ar, message: %s'git log --pretty=format:'%h : %s' --graph # 有的文字形化, 分支等.git log --pretty=format:'%h : %s' --topo-order --graph # 依照主分支排序git log --pretty=format:'%h : %s' --date-order --graph # 依照排序Git showgit show ebff # 查 log 是 commit ebff810c461ad1924fc422fd1d01db23d858773b 的容git show v1 # 查 tag:v1 的修改容git show v1:test.txt # 查 tag:v1 的 test.txt 案修改容git show HEAD # 此版本修改的料git show HEAD^ # 前一版修改的料git show HEAD^^ # 前前一版修改的料git show HEAD~4 # 前前前前一版修改的料Git reset 原git reset --hard HEAD # 原到最前面git reset --hard HEAD~3git reset --soft HEAD~3git reset HEAD filename # staging area 回到 unstaging 或 untracked (案容不改)Git grepgit grep "te" v1 # 查 v1 是否有 "te" 的字串git grep "te" # 查在版本是否有 "te" 的字串Git stash 存git stash # 存git stash list # 列出所有存的料git stash pop # 取出最新的一, 移除.git stash apply # 取出最新的一 stash 存料. 但是 stash 料不移除git stash clear # 把 stash 都清掉Git merge 合git mergegit merge mastergit merge new-branch下述自: ihower 的 Git 版本控制系(2) branch 分支和操作端 repo.x
Straight merge 的合模式,有全部的被合的 branch commits 加上一 merge-commit,看有 Parents ,保留所有 commit log。Squashed commit 成只有一 merge-commit,不有被合的 log。SVN 的 merge 即是如此。cherry-pick 只合指定的 commitrebase更 branch 的分支:找到要合的 branch 的共同的祖先,然後先只用要被 merge 的 branch commit一遍,然後再用目前 branch 再 commit 上去。方式合分享人的 local branch,因等於砍掉重commit log。Git blamegit blame filename # 於此案的所有 commit Git 原已被除的案git ls-files -d # 查看已除的案git ls-files -d | xargs git checkout -- # 已除的案原 Git git gc # 整理前和整理後的差, 可由: git count-objects 看到.git fsck --fullGit revert 料原git revert HEAD # 回到前一次 commit 的git revert HEAD^ # 回到前前一次 commit 的git reset HEAD filename # staging area 回到 unstaging 或 untracked (案容不改)git checkout filename # unstaging 回到最初 Repository 的案(案容回修改前)指令操作
git merge <branch_name> # 合另一 branch,若有 conflict 突直接 commit。若需要解突再多一 commit。git merge --squash <branch_name> # 另一 branch 的 commit 合一,特合需要做的 fixes bug 或 new feature,最後只留果。合完不你先 commit。git cherry-pick 321d76f # 只合特定其中一 commit。如果要合多,可以加上 -n 指令就不先你 commit,可以多 pick要合的 commit,最後再 git commit 即可。
以下 端 Repository 相
Git remote 端案git remotegit remote add new-branch http://git.example.com.tw/project.git # 增加端 Repository 的 branch(origin -> project)git remote show # 秀出在有多少 Repositorygit remote rm new-branch # 掉git remote update # 更新所有 Repository branchgit branch -r # 列出所有 Repository branch抓取 / 切 Repository 的 branchgit fetch origingit checkout --track -b reps-branch origin/reps-branch # 抓取 reps-branch, 此 branch 建立於 local 的 reps-branch除 Repository 的 branchgit push origin :heads/reps-branch