Pro Git閱讀筆記

Submitted by saladlam on

Pro Git(Scott Chacon, 2007)的筆記。

1. git是記錄快照(snapshot),不是記錄差異(difference)
2. git可用於local environment,即是不用連上network
3. git設定檔
- .git/config
- ~/.gitconfig (--global)
- /etc/gitconfig
4. User資料
- git config --global user.name "John Doe"
- git config --global user.email johndoe@example.com
5. 在工作目錄中初始化新倉庫
- git init
6. 從server clone一份code
- git clone git://github.com/schacon/grit.git
7. git不會自動monitor檔案,要手動add(從untracked到staged)
- git add file.c
8. git也會自動把modified file入staged,要手動
- git add file.c
9. 若果一個file己在staged,你又去改,再之後再git add,第一次那個 staged的內容會不見
10. 查那些file己staged or modify
- git status
11. modified同staged file不同
- git diff
12. staged同committed file不同
- git diff --cached
13. commit change
- git commit -m "Story 182: Fix benchmarks for speed"
14. 查commit history
- git log
- git log --pretty=format:"%h %s" --graph
15. 修改最後一次commit
- git commit --amend
16. 取消已經staged的文件
- git reset HEAD file.c
17. 把modified文件還原unmodified
- git checkout – file.c
18. 加入remote repository
- git remote add pb git://github.com/paulboone/ticgit.git
19. 抓remote有,但local沒有的資料
- git fetch pb
20. push data to remote repository
- git push [remote-name] [branch-name]
21. 列出現有tag
- git tag
- git tag -l 'v1.4.2.*'
22. add有command的tag(留意會mark在現在commit的位)
- git tag -a v1.4 -m 'my version 1.4'
- git show v1.4
23. 把 tag送上remote repository
- git push origin [tagname]
24. add branch(留意會mark在現在commit的位)
- git branch [name]
25. show all branch
- git branch --all (有*代表HEAD pointer)
26. 跳去另一個branch(唔知會否影響未commit的檔案)
- git checkout testing
27. delete branch(若果要delete的branch)
- git branch -d [name]
28. merge branch(把另一個branch的資料merge進HEAD pointer所在的branch)
- git checkout [name]
- git merge [anothername]
29. 遇到衝突時的merge branch
- git checkout [name]
- git merge [anothername]
- edit files to solve conflict
- git commit
30. 尚未merge的工作
- git branch --no-merged
31. 查看哪些分支已被併入當前分支
- git branch --merged
32. 把remote repository更新抄回local(在local的origin/master是上次remote repository更新的最後位
- git fetch origin
33. 推送local branch
- git push origin [localbranch]:[remotebranch]
34. 將master的東西rebase入experiment
- git checkout experiment
- git rebase master
35. merge會把兩個branch join埋一齊,但rebase不會
- 一般我們使用rebase的目的,是想要得到一個能在remote branch上乾淨應用的補丁
36. 一旦某個branch發佈到remote repository,就千萬不要再對該branch進行rebase。
37. branch, merge, rebase log
- git reflog
38. 臨時save work
- git stash
39. show臨時save work
- git stash list
40. 取回你臨時save work
- git stash apply [stash] (Don’t remove entry in list)
- git stash pop [stash] (Remove entry in list)
41. 臨時save work後,有時不能還原。利用這個去開一個新branch
- git stash branch [branch] [stash]

Add new comment

The content of this field is kept private and will not be shown publicly.

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
CAPTCHA
Enter the characters shown in the image.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.