SVN and Git Common Used Command
- SVN Common Commands
- Git Common Commands
- Git Commands Used Use in HW
- Git Commands Summary from WebSite
- How to Push an Exist Repository to Another
- Create New Repository
- Git Config the User Profile
- Add Modify and Delete Files from Repository
- Code Commit to Remote Git Repository
- Git Branch Management Local or Remote
- Git Tag Operation Local and Remote
- Look up Information in Git Repository
- Remote Operation
- Rollback and Revert from History Commit
- Other
- Appendix
SVN Common Commands
- Create a new branch
svn cp -m “Add a jTTS_EB9 brandh.”
http://10.0.0.6:8080/svn/jTTS5_0/branches/jTTS6.2.0/src/Product/Engine/jTTS_EB
http://10.0.0.6:8080/svn/jTTS5_0/branches/jTTS6.2.0/src/Product/Engine/jTTS_EB9
- SVN export the code without svn info
svn export http://10.0.0.6:8080/svn/jTTS5_0/branches/jTTS6.2.0/src/Product
- SVN checkout specifiyc version from respotory
svn co -r 3096 http://10.0.0.6:8080/svn/jTTS5_0/branches/jTTS6.2.0/src/Product
- SVN commit local modify to remote
svn status 查看需要提交的文件
svn add 將需要提交的文件納入版本控制"M"
svn commit -m “增加:添加文件” http://10.0.0.6:8080/svn/jTTS5_0/branches/jTTS6.2.0/src/Product
- Pull master branch code to develop branch
cd br_feature001
svn merge http://svn_server/xxx_repository/trunk
如果需要預覽該刷新操作,可以使用svn mergeinfo命令,如:
svn mergeinfo http://svn_server/xxx_repository/trunk --show-revs eligible
或使用svn merge --dry-run選項以獲取更爲詳盡的信息
- Merge develop branch code to master branch
一旦分支上的開發結束,分支上的代碼需要合併到主幹。SVN中執行該操作需要在trunk的工作目錄下進行。命令如下:
cd trunk
svn merge --reintegrate http://svn_server/xxx_repository/branches/br_feature001
分支合併到主幹中完成後應當刪該分支,因爲在SVN中該分支已經不能進行刷新也不能合併到主幹。
- Create a tag from stable branch
產品開發已經基本完成,並且通過很嚴格的測試,這時候我們就想發佈給客戶使用,發佈我們的1.0版本
svn copy http://svn_server/xxx_repository/trunk http://svn_server/xxx_repository/tags/release-1.0 -m “1.0 released”
- Merge two version to current version
svn -r 148:149 merge http://svn_server/xxx_repository/trunk
- Deleate specfic tag
svn rm http://svn_server/xxx_repository/branches/br_feature001
svn rm http://svn_server/xxx_repository/tags/release-1.0
Git Common Commands
Git Commands Used Use in HW
- Pull all sub module code
git submodule update --init --recursive 8090 int vfp- List local and remote branch info
git branch -a- List remote repositories ssl url
git remote -v- One cmd to update every sub module
git submodule foreach "git checkout -f master- One cmd to fetch all module’s update
git submodule foreach “git fetch”- Reset all modify haven’t commited
git reset HEAD- 將本地修改的代碼還原到某分支
git reset --hard master_1014- git只下載固定分支代碼
git clone -b xxbranch ssh://xxx.git xxxx_dir --depth 1- 一鍵下載主子倉
git clone -b xxbranch --recursive ssh://xxx.git xxxx_dir --depth 1- git創建本地及遠端自已分支(分支備份)
1、git branch test //創建基於當前分支的本地分支;
2、git push origin test //將遠端分支推到遠端;
3、git checkout -f test //切換當前分支到test;
4、git pull origin master //同步test分支到master;- 分支同步主線某分支
1.在主倉中加主線的地址
2.git pull main br_xxxx
3.git submodule foreach “git pull man br_xxx”
4.如果有衝突,解決衝突
5.解決衝突後,push到遠端自己分支去
6.同步完成- git add 文件後撤銷
git status 先看一下add 中的文件
git reset HEAD 如果後面什麼都不跟的話 就是上一次add 裏面的全部撤銷了
git reset HEAD XXX/XXX/XXX.java 就是對某個文件進行撤銷了- git 從某分支某次commit 拉分支並提交到遠端
git checkout 17a852f834ccea28f4830fa427b6b31b31388772 -b rst_frame_study
git push origin rst_frame_study
Git Commands Summary from WebSite
How to Push an Exist Repository to Another
Existing Git repository
cd existing_repo
git remote rename origin old-origin
git remote add origin http://gitlabhome.lenovopcsd.com/cuisdk/CUISDKrt.git
git push -u origin --all
git push -u origin --tags
Create New Repository
- Create a new repository at current directory .
git init- Create a new directory and take it as a repository
git int [project-name]- download a project and it’s code history
git clone [url]
Git Config the User Profile
Git的設置文件爲.gitconfig,它可以在用戶主目錄下(全局配置),也可以在項目目錄下(項目配置)。
- Show Current Git Config
git config --list- Edit Git config file
git config -e [–global]- Set Userinfo and email address Commit code will used.
git config [–global] user.name “[name]”
git config [–global] user.email "[email address]
Add Modify and Delete Files from Repository
#查看狀態
$ git status
#査看變更內容
$ git diff
#添加指定文件到暫存區
$ git add [ filel ] [ file 2] ...
#添加指定目錄到暫存區,包括子目錄
$ git add [ dir ]
#添加當前目錄的所有文件到暫存區
$ git add .
#添加每個變化前,都會要求確認
#對於同一個文件的多處變化,可以實現分次提交
$ git add -p
#刪除工作區文件,並且將這次刪除放入暫存區
$ git rm [ filel ] [ file 2] ...
#停止追蹤指定文件,但該文件會保留在工作區
$ git rm --cached [ file ]
#改名文件,並且將這個改名放入暫存區
$ git mv [ file - original ] [ file - renamed ]
Code Commit to Remote Git Repository
#提交暫存區到倉庫區
$ git commit -m [message]
# 提交暫存區的指定文件到倉庫區
$ git commit [filel] [file2] ... -m [message]
#提交工作區自上次 commit 之後的變化,直接到倉庫區
$ git commit -a
# 提交時顯示所有 diff 信息
$ git commit -v
# 使用一次新的 commit ,替代上一次提交
# 如果代碼沒有任何新變化,則用來改寫上一次 commit 的提交信息
$ git commit --amend -m [message]
# 重做上一次 commit ,幷包括指定文件的新變化
$ git commit --amend [filel] [file2] ...
Git Branch Management Local or Remote
#顯示所有本地分支
$ $ git branch
# 列出所有遠程分支
$ git branch -r
# 列出所有本地分支和遠程分支
$ git branch -a
# 新建一個分支,但依然停留在當前分支
$ git branch [branch-name]
# 新建一個分支,與指定的遠程分支建立追蹤關係
$ git branch --track [branch] [remote-branch]
# 刪除分支
$ git branch -d [branch-name]
# 刪除遠程分支
$ git push origin --delete [branch-name]
$ git branch -dr [remote/branch]
# 新建一個分支,並切換到該分支
$ git checkout -b [branch]
# 切換到指定分支,並更新工作區
$ git checkout [branch-name]
#切換到上一個分支
$ git checkout -
# 建立追蹤關係,在現有分支與指定的遠程分支之間
$ git branch --set-upstream [branch] [remote-branch]
# 合併指定分支到當前分支
$ git merge [branch]
# 衍合指定分支到當前分支
$ git rebase <branch>
# 選擇一個 commit ,合併進當前分支
$ git cherry-pick [commit]
Git Tag Operation Local and Remote
$ git tag #列現所有本地標籤
$ git tag <tagname> #基於最新提交創建標籤
git tag -d <tagname> #刪除標籤
# 刪除遠程 tag
$ git push origin :refs/tags/[tagName]
# 查看 tag 信息
$ $ git show [tag]
# 提交指定 tag
$ git push [remote] [tag]
# 提交所有 tag
$ git push [remote] --tags
# 新建一個分支,指向某個 tag
$ git checkout -b [branch] [tag]
Look up Information in Git Repository
#顯示有變更的文件
$ git status
# 顯示當前分支的版本歷史
$ git log
#顯示 commit 歷史,以及每次 commit 發生變更的文件
$ git log --stat
# 搜索提交歷史,根據關鍵詞
$ git log -S [keyword]
# 顯示某個 commit 之後的所有變動,每個 commit 佔據一行
$ git log [tag] HEAD --pretty=format:%s
# 顯示某個 commit 之後的所有變動,其 " 提交說明"必須符合搜索條件
$ git log [tag] HEAD --grep feature
# 顯示某個文件的版本歷史,包括文件改名
$ git log --follow [file]
$ $ git whatchanged [file]
# 顯示指定文件相關的每一次 diff
$ git log -p [file]
# 顯示過去 5 次提交
$ git log -5 --pretty --oneline
# 顯示所有提交過的用戶,按提交次數排序
$ git shortlog -sn
#顯示指定文件是什麼人在什麼時間修改過
$ git blame [file]
# 顯示暫存區和工作區的差異
$ git diff
# 顯示暫存區和上一個 commit 的差異
$ git diff --cached [file]
# 顯示工作區與當前分支最新 commit 之間的差異
$ git diff HEAD
# 顯示兩次提交之間的差異
$ git diff [first-branch]...[second-branch]
# 顯示今天你寫了多少行代碼
$ git diff --shortstat "@{0 day ago}"
# 顯示某次提交的元數據和內容變化
$ $ git show [commit]
# 顯示某次提交發生變化的文件
$ $ git show --name-only [commit]
# 顯示某次提交時,某個文件的內容
$ git show [commit]:[filename]
# 顯示當前分支的最近幾次提交
$ git reflog
Remote Operation
# 下載遠程倉庫的所有變動
$ git fetch [remote]
# 取回遠程倉庫的變化,並與本地分支合併
$ git pull [remote] [branch]
# 顯示所有遠程倉庫
$ git remote -v
#顯示某個遠程倉庫的信息
$ git remote show [remote]
# 增加一個新的遠程倉庫,並命名
$ git remote add [shortname] [url]
#上傳本地指定分支到遠程倉庫
$ git push [remote] [branch]
# 強行推送當前分支到遠程倉庫,即使有衝突
$ git push [remote] --force
# 推送所有分支到遠程倉庫
$ git push [remote] --all
$ git push 〈 remote 〉: <branch/tag-name> #刪除遠程分支或標籤
$ git push --tags #上傳所有標籤
Rollback and Revert from History Commit
$ git reset --hard HEAD #撤銷工作目錄中所有未提交文件的修改內容
$ git checkout HEAD < file > #撤銷指定的未提交文件的修改內容
$ git revert < commit > #撤銷指定的提交
$ git log -- before="l days " #退回到之前1天的版本
#恢復暫存區的指定文件到工作區
$ git checkout [file]
#恢復某個 commit 的指定文件到暫存區和工作區
$ git checkout [commit] [file]
#恢復暫存區的所有文件到工作區
$ git checkout .
#重置暫存區的指定文件,與上一次 cormnit 保持一致,但工作區不變
$ git reset [ file ]
#重置暫存區與工作區,與上一次 commit 保持一致
$ git reset --hard
#重置當前分支的指針爲指定 commit ,同時重置暫存區,但工作區不變
$ git reset [ commit ]
#重置當前分支的 HEAD 爲指定 commit ,同時重置暫存區和工作區,與指定 commit —致
$ git reset --hard [commit]
# 重 置 當 前 HEAD 爲指定 commit ,但保持暫存區和工作區不變
$ git reset --keep [commit]
# 新建一個 commit ,用來撤銷指定 commit
#後者的所有變化都將被前者抵消,並且應用到當前分支
$ git revert [commit]
#暫時將未提交的變化移除,稍後再移入
$ git stash
$ git stash pop
Other
Generate a distributed package.
- git archive
Appendix
Git Cmd Quick Search
#創建版本庫
$ git clone <url> #克隆遠程版本庫
$ git init #初始化本地版本庫
#修改和提交
$ git status #查看狀態
$ git diff #查看文件修改
$ git add . #跟蹤所有改動過的文件
$ git add <file> #跟蹤指定的文件
$ git mv <old> <new> #文件改名
$ git rm <file> #刪除文件
$ git rm --cached <file> #停止跟蹤文件但不刪除
git commit -m "commit message" # 提交所有更新過的文伴 〃
git commit --amend #修改最後一次提交
#查看提交歷史
$ git log #查看提交歷史
$ git log -p <file> #查看指定文件的提交歷史
$ git blame <file> #以列表方式查看指定文件的提交歷史
#撤消
$ git reset --hard HEAD #撤消工作目錄中所有未提交文件的修改內容
$ git checkout HEAD <file> #撤消指定的未提交文件的修改內容
$ git revert <commit> #撤消指定的提交分支與標籤
#分支與標籤
$ git branch #顯示所有本地分支
$ git checkout <branch/tag> #切換到指定分支或標籤
$ git branch <new-branch> #創建新分支
$ git branch -d <branch> #刪除本地分支
$ git tag #列出所有本地標籤
$ git tag <tagname> #基於最新提交創建標籤
$ git tag -d <tagname> #刪除標籤
#合併與衍合
$ git merge <branch> #合併指定分支到當前分支
$ git rebase <branch> #衍合指定分支到當前分支
#遠程操作
$ git remote -v #查看遠程版本庫信息
$ git remote show <remote> #查看指定遠程版本庫信息
$ git remote add <remote> <url>
#添加遠程版本庫
$ git fetch <remote> #從遠程庫獲取代碼
$ git pull <remote> <branch> #下載代碼及命速合併
$ git push <remote> <banch> # 上&代碼及快速合併
$ git push <remote> :<branch/tag-name> #刪除遠程分支或標籤
$ git push --tags #上傳所有標籤