工做必備:git
【更新master】
git checkout master
git pull
git checkout zyb/FirstCommit
git merge masterweb
//git rebase master --> 更新 zyb/FirstCommit 分支到 master 的最新版本緩存
【屢次 commit,日誌太多,處理方法:】
git log --graph [git log 某次提交號(適用於不少次commit的狀況)]
git reset **[建立此branch前的編號]
git log [建立此branch到最後一次commit間的log會被刪除]
git add . [撤銷:git reset HEAD <file>...]
git commit -m "commentment"
git push -f origin zyb/FirstCommit 【必定是 push 到本身的branch,-f 是由於log不一致】app
【建立並提交分支】
git status
git pull
git checkout -b zyb/FirstCommit
git branch -b zyb/FirstCommit
git checkout zyb/FirstCommit
git diff --color
git add . [或*/*/*.sh]
git commit -m "commentment"
git push origin zyb/FirstCommitwebstorm
【git remote add origin 網址】
添加遠程主機,origin也是命名的,多是git最初的建議名ide
【分支】
刪除本地分支
git branch -d the_local_branch #### If you are sure you want to delete it, run 'git branch -D zyb/modifyApiServiceDevconf'.
git branch -D the_local_branch
刪除遠端分支(if you know what you are doing!)
git push origin :the_remote_branch
查看遠端分支
git branch -a
獲取遠端分支
git fetch,能夠將遠程分支信息獲取到本地
git fetch origin master
git fetch origin zyb/certainBranch
git checkout -b local-branchname origin/remote_branchname 就能夠將遠程分支映射到本地命名爲local-branchname 的一分支測試
【測試機搞一把】
git clone http://code.huawei.com/cloud-service-dev-team-devops/cloudwatch.gitfetch
【git 緩存http用戶名&密碼】
git config --global credential.helper 'cache --timeout=2592000'
git config --global credential.helper wincred --replace-all
刪除配置: git config --global --unset core.excludesfile
timeout 的時間單位爲秒,能夠自行修改. (示例中表示緩存 30 天)
設置完後,再使用 http 協議操做倉庫時,只要輸入了一次用戶名和密碼,在緩存時效內就不須要再輸入了。
[可參考 http://pages.huawei.com/codeclub/guides ]ui
【【reset並解決衝突】】
1. reset到須要squash的版本號
git log ******* --graph
git reset *******的前一個
【這裏最好把版本號記錄在案,出錯後還能reset回去】
2. 更新master
git remote update
git pull origin master
通常在pull origin master的時候,git會提示沒法執行,並建議move或remove一些文件,這些文件若是是本身改過的就move,pull以後再拷貝回來;若是不是本身的,直接rm
若是其建議你commit或stash,能夠這樣
git stash
git pull origin master
git stash pop
3. 處理conflict
使用webstorm的GUI,右鍵工程任意目錄或文件,選擇 Git - Resolve conflicts
Changes to be committed:
若是是本身的,不用管了;
若是不是本身修改的,使用 git reset HEAD <file> ... 撤銷[從工做區放回暫存區]
Changes not staged for commit:
若是是本身的,使用 git add <file> ...
若是是本身刪除的,使用 git rm <file> ...
【Attention:git add/rm 都會被提交】
若是不是本身修改的,使用 git checkout -- <file>... 撤銷[從暫存區刪除]
Untracked files:
若是是本身的,使用 git add <file> ...
不然,忽略
4. 提交併推到遠端
git commit -m "comments"
git push origin zyb/FirstCommit -f [因爲使用了reset,版本號已經不符合要求了,因此-f]this
【【git stash】】
git stash list
git stash pop
git stash apply stash@{1}
git reset --hard origin/master
之後若是不當心在master上改代碼了,能夠用這個恢復本地的master
git reset --hard HASH #返回到某個節點,不保留修改。
git reset --soft HASH #返回到某個節點。保留修改
【Your branch is ahead of 'origin/master' by 3 commits.】
You get that message because you made changes in your local master and you didn't push them to remote. You have several ways to "solve" it and it normally depends on how your workflow looks like:
In a good workflow your remote copy of master should be the good one while your local copy of master is just a copy of the one in remote. Using this workflow you'll never get this message again. If you work in another way and your local changes should be pushed then just git push origin assuming origin is your remote If your local changes are bad then just remove them or reset your local master to the state on remote git reset --hard origin/master