記錄git 使用範例
更新記錄
| item | note | xx | 
|---|---|---|
| 20161102 | 新增: 如何建立及刪除tag | |
| 20161110 | 修正: 如何建立及刪除tag | git push origin refs:tags/v3.2000.9 –> 改為 –> git push origin :refs/tags/v3.2000.9 | 
| 20170630 | 增加:未push之前還原方式 | 
未push之前還原方式
- 砍掉 commit 重來,但是修改的程式還是留在 working tree 
 git reset HEAD^ 就會回到前一版本(一個^表示是前一版),並把其中的 changes 繼續留在 working tree 中- 1 - git reset HEAD^ 
- changes 直接加到 staging area - 1 - git reset --soft HEAD^ 
- 完全抹掉前一次的 commit - 1 - git reset –hard HEAD^ 
GIT / 如何由其它Project的branch同步進來資料
當有Project,需要cherry-pick不同Project的branch update
- push branch 至別的 repo.
git push git@bitbucket.org:erwin_chang/nknvr.git develop:from-nvr-project
- 要在 nknvr 更新 from-nvr-project 時
| 1 | git checkout from-nvr-project | 
感謝Peter提供
如何checkout檔案,特定某一版(即git commit)
- 82f5 為你的git commit的md5
| 1 | git checkout 82f5 some.file another.file | 
如何查看目錄的修改記錄
- git log 目錄名稱
| 1 | $ git log ez-ipupdate | 
- 其它
| cmd | note | 
|---|---|
| git log | 查看全部修改記錄 | 
| git log -3 | 查看最新的3筆記錄 | 
| git log 目錄 | 查看此目錄修改記錄 | 
| git log 檔案 | 顯示檔案修改記錄 | 
- 查看檔案內的此function相關修改記錄
| 1 | git log -L '/int main/',/^}/:./monitor/main.c | 
- git log command
| 1 | NAME | 
如何建立及刪除tag
- 查看目前的tag 
 git tag -l- 1 
 2
 3
 4
 5
 6- $ git tag -l 
 2.1845.1
 2.1853.1
 2.1860.10
 2.1860.11
 2.1860.12
- 建立local tag ,並且同步到server - 1 
 2- git tag -a v3.2000.9 
 git push origin v3.2000.9
- 刪除tag (同時移除local及server的tag) - 1 
 2- git tag -d v3.2000.9 
 git push origin :refs/tags/v3.2000.9
- git tag -help - 1 
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27- $ git tag -help 
 usage: git tag [-a|-s|-u <key-id>] [-f] [-m <msg>|-F <file>] <tagname> [<head>]
 or: git tag -d <tagname>...
 or: git tag -l [-n[<num>]] [--contains <commit>] [--points-at <object>]
 [<pattern>...]
 or: git tag -v <tagname>...
 -l, --list list tag names
 -n[<n>] print <n> lines of each tag message
 -d, --delete delete tags
 -v, --verify verify tags
 Tag creation options
 -a, --annotate annotated tag, needs a message
 -m, --message <message>
 tag message
 -F, --file <file> read message from file
 -s, --sign annotated and GPG-signed tag
 --cleanup <mode> how to strip spaces and #comments from message
 -u, --local-user <key id>
 use another key to sign the tag
 -f, --force replace the tag if exists
 --column[=<style>] show tag list in columns
 Tag listing options
 --contains <commit> print only tags that contain the commit
 --points-at <object> print only tags of the object