新feature流程
Git checkout <new branch>
修改,commit 後
git checkout develop
git pull –rebase
git merge --squash <new branch> //去除多次提交
git status //查看是否有衝突,使用eclipse處理後 git add .
git diff --cached # double check your diff
git commit –F ~/commit
git push
git branch –D <new branch>
修復bug流程
按上面步驟合併到develop分支後,執行:
git checkout master;
git pull--rebase;
git cherry-pickcommitId //develop的commitId
git push
忘記創建分支
未向develop提交
git checkout -b <new-branch>
已向develop提交
git add -A # 繼續在develop上操作,add allfiles you haven't committed
git commit
git pull --rebase
git checkout -b <new branch>
git checkout develop
git reset --hard origin/develop //回覆本地develop爲遠端版本
git checkout <new-branch>
從 development向new branch 更新
$ git checkout <feature-branch>
$ git rebase development
撤銷修改
git reset --soft HEAD^ 放棄最新的commit
git reset HEAD 使用工作區替換index
git checkout HEAD --file(.) : 版本庫替換index和工作區文件
git clean -fd :清除沒有加入版本庫的文件和目錄 untracked;
忽略文件
git update-index --assume-unchanged <file…> ignore一個文件
git update-index --no-assume-unchanged<file…> 重新track文件
git ls-files -v|grep -e"^h.*" 查看哪些文件被忽略
log記錄
git log --since="2 days ago"--until="1 hour ago 某一時間段日誌
git log --oneline –decorate --all
git log --graph --pretty=oneline --stat 顯示變更摘要:每個commit一行,並顯示提交關係
git log -p -1
lg = log --graph --pretty=format:'%Cred%h%Creset-%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'--abbrev-commit --date=relative
其他命令
git status -sb : 顯示版本和分支
git add -A 和 git add-u
git add –I (提供交互式界面,選擇式添加)
gitp checkout -b <newbranchname> 創建並切換到新分支
git checkout <commit>: 整個工作區切換到歷史版本
git checkout <commit> --file: 檢出某文件的歷史版本
git push origin +master:master 強制推送
git push -u origin new_branch 建立遠端 new_branch並推送
git branch --track 遠端branch 建立一個 tracking 遠端 branch 的 branch,這樣以後 push/pull都會直接對應到該遠端的branch。
git branch --set-upstream 遠端branch 將一個已存在的 branch 設定成 tracking 遠端的branch。
find ./ -name "*.xml" | xargs grep "jdbc/jndi-otcp-aus"
git commit --amend -m "新message" 修改上次的提交說明