Git

Git is a free and open source distributed version control system.
Git Init
In 33.5:/home/develop/cancan
$ GIT_DIR="test.git" git init --shared=allIn local:
- git clone 取得 source code
- move source in git folder
$ git add * $ git commit $ git push ssh://orson@10.62.38.168/home/develop/cancan/test.git master
取得 Source Code
git clone orson@10.62.38.168/sandbox.git
新增檔案
git add modify-file
更新本地檔案
git pull
刪除檔案
git rm filename
修改檔名、搬移目錄
git mv filename new-filename
觀看狀態
git status
Commit
git commit -m 'commit message'
git commit -a --amend -m “new commit" # 修正上一個 Commit
更新遠端檔案
git push
分支
git branch # 列出目前有多少 branch
git branch new-branch # 產生新的 branch
git branch -d new-branch # 刪除 new-branch
git branch -D new-branch # 強制刪除 new-branch
git branch -r # 列出所有 Repository branch
git branch -a # 列出所有 branch
切換
git checkout branch-name # 切換到 branch-name
git checkout master # 切換到 master
git checkout filename # 還原檔案到 Repository 狀態
git checkout HEAD . # 將所有檔案都 checkout 出來
比較
git diff master # 與 Master 有哪些資料不同
git diff tag1 tag2 # tag1, 與 tag2 的 diff
git diff HEAD # 比較目前位置與 Repository 差別
git diff new-branch # 比較目前位置與 branch 的差別
標記
git tag 中文 # tag 也可以下中文, 任何文字都可以
git tag -d 中文 # 把 tag=中文 刪掉
git push origin v1.5 # 上傳標籤到遠端
git push origin --tags # 上傳所有標籤到遠端
顯示
git log # 將所有 log 秀出
git log --all # 秀出所有的 log (含 branch)
git log -p # 將所有 log 和修改過得檔案內容列出
git log -p filename # 將此檔案的 commit log 和 修改檔案內容差異部份列出
git log --name-only # 列出此次 log 有哪些檔案被修改
git log --stat --summary # 查每個版本間的更動檔案和行數
git log filename # 這個檔案的所有 log
git show v1 # 查 tag:v1 的修改內容
git show HEAD # 此版本修改的資料
還原
git reset --hard HEAD # 還原到最前面
還原已被刪除的檔案
git ls-files -d # 查看已刪除的檔案
git ls-files -d | xargs git checkout -- # 將已刪除的檔案還原
搜尋
git grep "te" # 查現在版本是否有 "te" 的字串
git grep "te" v1 # 查 v1 是否有 "te" 的字串
合併
git merge
0 comments