//輸入git help查看所有的命令
git help
usage: git [--version] [--help] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
The most commonly used git commands are:
add Add file contents to the index
bisect Find by binary search the change that introduced a bug
branch List, create, or delete branches
checkout Checkout a branch or paths to the working tree
clone Clone a repository into a new directory
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
fetch Download objects and refs from another repository
grep Print lines matching a pattern
init Create an empty Git repository or reinitialize an existing one
log Show commit logs
merge Join two or more development histories together
mv Move or rename a file, a directory, or a symlink
pull Fetch from and integrate with another repository or a local bra
push Update remote refs along with associated objects
rebase Forward-port local commits to the updated upstream head
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
show Show various types of objects
status Show the working tree status
tag Create, list, delete or verify a tag object signed with GPG
//設置提交者信息
1.git config --global user.name "linxiaobai"
git config --global user.email "[email protected]"
可以用 git config --global --list來查看以上信息是否設置成功,如果直接用github客戶端打開過來的,上訴設置應該不用進行
2.git config --global color.ui "auto" 設置使用不同的顏色顯示不同類型的內容
3.將powershell的當前目錄調至某一個目錄下(例如G盤下的gittest文件夾)裏面 然後mkdir test新建一個文件夾
cd test 進入
4.隨時查看當前路徑可以輸入 pwd 指令
5.輸入git init創建版本庫
6.New-Item 簡寫 ni hello.php type輸入 file 即文件
7. notepad hello.php 對hello.php進行編輯
<?php
$str = "hello php";
var_dump($str);
?>
編輯完成後strl+s保存,然後alt+F4退出編輯
8.git add hellp.php 將文件添加到版本庫的索引
9.git status查看當前文件的狀態,看到顯示Initial commit 初始化提交,即git add後進入的是預提交的狀態
10.git commit -m "add a hello.php" //-m後面跟的是類似說明的文字
直接寫git commit 不加後面會彈出一個notepad編輯,然後在裏面輸入效果和 -m後輸入是一樣的
提交後再輸入git status可以發現已經沒有要提交的內容了,說明剛纔的文件提交成功
11.熟練使用一下以上命令,新建一個TT.java,然後什麼都不寫,直接add加commit,然後修改TT.java爲它增加HelloWorld內容
然後輸入git status查看狀態,發現提示你修改過了文件但是沒有提交,這時候直接git commit -a提交,不用預提交
12.接下來創建一個分支再在分支上建一個Hello.c後合併分支
1) git branch RB_1.0 master
2) git checkout RB_1.0 //發現powershell裏面的前面高亮區域從master變爲RB_1.0
3) 建立Hello.c並提交和上面類似
處理髮布
4)git tag 1.0 RB_1.0
5) git tag //查看剛纔打過的標籤
6)git checkout master 切換回去主分支
7)git rebase RB_1.0
8) git branch -d RB_1.0 刪除分支
如何給1.0.x分支打補丁
9)git branch RB_1.0.1 1.0
/*
G:\git\mygithub\test2 [master]> git branch RB_1.0.1 RB_1.0
fatal: Not a valid object name: 'RB_1.0'.
G:\git\mygithub\test2 [master]> git branch RB_1.0.1 1.0
*/
給代碼發佈創建歸檔微距,沒有必要總是把歷史記錄一起發佈,通常情況下,把標籤對應的版本內容打包成一個tar或是zip包
10)git archive --format=tar\--prefix=test2-1.0/1.0\>test2-1.0.zip //有點小問題,不知道什麼原因
同步到GitHub
/*以下方式同步到GitHub發現不行*/
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/linxiaobai/bb.git
git push -u origin master
先在GitHub上面建一個版本庫,然後用以下命名克隆到本地
git clone https://github.com/linxiaobai/bb.git bb-remote
cd bb-remote
然後各種修改後commit後,用git push就可以上傳到GitHub上了
發現一個非常不錯的git教程 http://www.ihref.com/read-16369.html 看這個吧,進階一下~