git checkout master
git pull --rebase
// switch the working branch to master branch
// then, pull the things back.
// these things includes: the commits on master by your colleagues and
// other branch name created by your colleagues
// Then, update master branch to the latest commit
// combo 技
// 切換到 master, 把其他人做的更動拉回來
// 然後快轉到 master 最新的 commit 狀態
// 拉回來的東西包括了: 其他人在 master 上的 commit 跟其他人創立的 branch name
git checkout -b newBranchName
// 創立一個 local的新的branch 叫做 newBranchName
// 然後切換過去
git branch --track workingLocalBranchName remote/remoteBranchName
// creates a local working branch name, called "workingLocalBranchName"
// which is tracking the remote branch name called "remoteBranchName".
// the remote branch name can be found by "git branch -a"
/*
通常早上做完這兩個指令以後
就開始寫 code
到下午, code改完了, bug修掉了以後 ...
*/
git gui
// it is better to do the commit and push here
// 最好在這裡做 commit 跟 push
gitk
// see the history of commits of the current branch
// each commit is identifed with unique SHA string, which can be found in this window
// 看目前 branch 的歷史紀錄
// 每一次 commit 都有一個 SHA id 對應
// 在這個畫面裡面可以看到每次 commit 的SHA id
/*
做 patch 了, 大家來 review
*/
git format-patch -1 --full-index
// if your modification only requires 1 commit
// this command is quicker
// 如果你只 commit 了一次
// 這個指令會做出這個 commit 的 patch 檔
git diff --full-index oldSHA..newSHA > patchFileName.patch
// diff all the commits from oldSHA to newSHA into the patchFileName.patch
// 把從 oldSHA 到 newSHA 的所有更動放到 patchFileName.patch
git diff --full-index master..localBranchName > xxx.patch
// diff between two branches
// 兩個 branch 做diff
/*
merge 到 master
*/
git cherry-pick SHA
// SHA represents a commit, no matter which branch it is on.
// this command grabs the commit identified by that SHA id,
// and put it on top of the local working branch.
// 把SHA所代表的那個 commit 拉過來, 丟到你打指令的這個 branch
git merge --squash localBranchName
// merge the working branch with localBranchNamebranch
// 把 localBranchName這個 branch 拉過來, merge到你打指令的這個 branch
git merge --squash origin/remoteBranchName
// merge with remoteBranchName branch
// 與遠端的 branch 做 merge
/*
如果 merge 有conflict... 請小心, 沒有指令可以幫你處理好conflict
*/
git reset --hard SHA
// 說對不起, 我想清楚再merge
// 回到SHA這個commit, 在這之後的commit都會不見
// 回到SHA這個commit, 在這之後的commit都會不見
git reset --soft SHA
// 說對不起, 我想清楚再merge
// 回到SHA這個commit, 在這之後的commit都會變成已修改狀態
// 回到SHA這個commit, 在這之後的commit都會變成已修改狀態
git gui
// 如果修好了conflict 記得要再 commit 一次
/*
其他指令
*/
git checkout localBranchName
// change the working branch to localBranchName branch
// ex: git checkout master
// Before checking out to another branch, there should not be any
// editting modifications in the working branch.
// Make sure you stash or commit everything you've modified
// 更改你目前的打指令的這個 branch 到 localBranchName 這個 branch
// 更改 branch 之前, 必須確定目前的 branch 是乾淨的
// 所以, 所有的更動請先放到stash或是commit
git checkout -b newLocalBranchName origin/remoteBranchName
// Grab the remoteBranchName into newLocalBranchName
// 把遠端 remoteBranchName 整串拉回來, 放到 newLocalBranchName
git status
// see the current status of tracked files,
// or any new files that are not tracked.
// 看目前git 追蹤的檔案裡面, 那些做過更改
// 或是那些檔案沒有被tracked
// put the current modifications into the stash area.
// it will 'clean' the current modifications and restore to
// the lastest commit
// 把目前所做的更動放到stash, 會把目前的更動清掉,
// 恢復到最新的commit的狀態
git stash apply -1
// apply the first stash item from the stash area to the current editting files.
// 把stash裡面第一個東西拉出來, 對目前的檔案做更動
git stash clear
// clear the stash area
// 把 stash 清掉
git push origin:remoteBranchName
git push origin --delete remoteBranchName
git push origin --delete remoteBranchName
// Remove remoteBranchName on the remote side.
// 把遠端的一個叫做 remoteBranchName 的 branch 殺掉
git branch -D localBranchName
// remove the localBranchName branch
// 把本地端的 localBranchName 這個 branch 殺掉
// 新的gerrit server有內建code review的功能
/*
以前都是做patch
丟上review board
過了以後
再cherry-pick到master branch
這個對我來說的新功能是
remote的branch有兩個同名同姓的
只是在不同的refs的HEAD
要先push到HEAD:refs/for/
commit就會出現在review board上了
review過了以後
這個 commit就會跑到 remote/origin/
*/
git push origin HEAD:refs/for/<remoteBranchName>
git apply --stat XXX.patch // see the stats of the patch files
git apply --check XXX.patch
git apply XXX.patch
// git ignore mode changes:
git config core.filemode false
// list files changed between two SHAs:
git diff --name-only SHA1 SHA2
沒有留言:
張貼留言