Más contenido relacionado La actualidad más candente (20) Similar a Git and git hub (20) Git and git hub2. This version will no longer be maintained
Please checkout the new version of this slide
https://lee-w.github.io/git-tutorial/#/
8. What’s version control?
有沒有code改著改著就回不去了的經驗?
你需要的就是版本控制!!!
打Game要存檔,打Code當然也要存檔!!!
那多複製個幾份不就好了? 占空間、難維護
Git只會記錄每一次有差異的部分,但使用起來就像存了很多檔一樣
10. Install Git For Linux
Fedora
Debian, Ubuntu
yum install git-core
sudo apt-get install git
11. Install Git For Mac
使用MacPorts
MacPorts
http://www.macports.org/
使用brew
brew
http://brew.sh/
sudo port install git-core +svn +doc +bash_completion +gitweb
brew install git
13. Set e-mail and name
一開始會要求要設定名稱和email才能使用
一般來說就設定 git hub 或 bitbucket比較好
雖然也可以設定無效的,但push repo上去的時候就會是unknown上傳的
指令:
e.g.
git config --global user.name "<Your name>“
git config --global user.email "<Your email>"
git config --global user.name user
git config --global user.email user@user
14. Set alias
以自訂的短文字來取代長長的指令 -> 懶人必備!!!
指令:
下面是我設定的alias
git config --global alias."command alias" "original command“
git config --global alias.st status
git config --global alias.cmt commit
git config --global alias.cmtm "commit –m"
git config –global alias.br branch
16. Let’s start a repo in local
What’s repo
repository , git 都是這麼稱呼它的版本資料庫
將一個專案(其實就是資料夾啦)加入git追蹤
git init
18. Let’s start a repo in local
出現了一個.git的隱藏資料夾!!!
這是儲存git紀錄的地方,沒事不要去動它
19. Let’s start a repo in local
出現了一個.git的隱藏資料夾!!!
這是儲存git紀錄的地方,沒事不要去動它
這是oh my zsh的功能
21. Stage
總共有分成4個階段
0. untracked (新的檔案,根本還沒加入整個git版本控制的流程內)
1. unmodified (完成add ,但還沒commit)
2. modified (add了之後又修改 )
3. staged (commit完成 ,從此以後記錄檔就存好了)
29. Stage - staged
不過開啟編輯器有點麻煩
透過這個指令,就能在指令列完成commit
git commit –m “your commit for this change”
31. Stage - staged
上一個commit錯了,怎麼辦?
你需要的是
修改剛剛commit的內容
git commit --amend
34. Stage
新增檔案 => 加入 track (git add) => 提交 (git commit)
=> 繼續加入或修改其他檔案
修改檔案 => 加入 stage (git add) => 提交( git commit )
=> 繼續修改其他檔案
47. Reset V.S Checkout
1. 在hi2.txt又加入一個數字 2. reset到兩次以前 (second commit)
3. hi2.txt的內容還是沒變 4. checkout 5. 回復到second commit的內容了
48. Ignore file
有時候,有些檔案不想被加入git追蹤怎麼辦?
那就忽略它吧!!!
讓一些密碼或機密資料不要被追蹤和上傳
.gitignore內的檔案將不被git追蹤,如果在資料夾內就要把資料夾也打上去
e.g. 在aFolder下的b : echo aFolder/b > .gitignore
注意.gitignore不用也不能加./
注意這方法只適用在還沒加入追蹤的檔案
echo "filename" > .gitignore
50. Rename(move) and delete files
刪除已經被加入git追蹤的檔案
重新命名和移動位置
對於Linux而言,這兩件事基本上是相同的
git mv “original filename” “new filename”
git rm "filename"
54. Git Hub
What is Git Hub
一個可以將原始碼開放到網路
上的網站
很多強大的開放專案都來自這
p.s.私有專案是要付費的
56. Create a repo in Git Hub
為你的repo選個好名子,就可以Create repository了!!!
58. Push your repo
Push -> 簡單來說就是把你的檔案上傳到git hub
如果你還沒有一個git 專案,你可以照著他打
記得要把origin後面的網址改成你的repo的網址喔~
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/Lee-W/tryGit.git
git push -u origin master
59. Push your repo
比較重要的是這兩行
git remote是將遠端設定為你的repo,只需要設定一次
git push –u origin master就是把master分支傳到git hub上
當然也可以傳其他的branch
git remote add origin “Your repo”
git push -u origin master
60. What should be in a repo
你的程式碼
readme
右下角的readme
要用markdown的語法寫
Git Hub還有自己的一套markdown
Git hub Favored Markdown
通常會命名為readme.md
其實還有一些檔名git hub可以讀到
想知道就自己google吧!!!
61. Download a repo
這裡就要分成兩個支線了
1.如果你的電腦還沒有這個repo -> Clone a repo
2.如果你的電腦已經有這個repo了 -> Pull a repo
63. Pull a repo
如果你的電腦上已經有這個repo了
而且remote也是設定在這個repo上
這樣就可以把最新的版本抓下來
git pull
64. Pull a branch in a remote repo
透過這兩個指令,就可以把repo上特定的repo抓下來
git fetch origin
git pull origin “branch_name”
65. Other Remote Operation
顯示現在remote的點在哪
刪除remote的點
加入remote的點
git remote -v
git remote rm origin
git remote add origin “URL”
66. Other resource
這裡附上一些很棒的的git教學和資源
1. 寫給大家的 Git 教學
2. Git教學
3. 版本控制系統 Git 精要使用讓 Git 1.8 (iHower)
4. 30 天精通 Git 版本控管
5. Pro GIT (中譯)
6. Try Git (互動)
7. Learn Git Branching (互動)