git 常用命令

場景1, 臨時拉取feature branch做修改
emambp:learn emagitfetchoriginfeature/elinatestemambp:learnema git checkout -b elinatest origin/feature/elinatest

git remote update=git fetch

場景2,feature branch需要合併到master
master已經被其他同事更新了許多
目前在elinatest 分支, rebase master分支上別人的更新
git rebase master
如果很久沒有更新,conflict肯定很多,需要解決conflict 然後執行git add

master維護者只需要直接根據你提的pr merge你的分支即可
git checkout master
git merge elinatest

場景3,針對feature branch 開發自己的code (分支開發)
git fetch origin feature/perf_jobs_master2mesos
git checkout -b perf_jobs_master2mesos origin/perf_jobs_master2mesos
此時 git log 看到
commit 1 lijing
balaba… 本地編寫代碼 過了幾天 完成
git commit -a -m “comment info”
此時 git log 看到
commit 3 shaofang
commit 1 lijing
git rebase origin/feature/perf_jobs_master2mesos
此時git log 看到
commit 3 shaofang
commit 2 lijing
commit 1 lijing
然後push 本地修改到feature
git push origin HEAD:feature/perf_jobs_master2mesos
此時查看遠端 repo branch發現 commit log
commit 3 shaofang
commit 2 lijing
commit 1 lijing
場景4,push代碼後 查看本地 發現HEAD值爲最新的commit 但FETCH_HEAD 爲次新commit 所以每次開發前或者每次準備push代碼前 最好fetch一下 更新一下該值(此時只是更新了指針索引 但本地的代碼沒有更新 只有rebase纔會更新遠端代碼到本地) 然後 rebase的時候將根據FETCH_HEAD的值rebase 遠端最新 code到本地

emambp:jenkins emacat.git/HEADref:refs/heads/perfjobsmaster2mesosemambp:jenkinsema cat .git/FETCH_HEAD
b87369608ef3a3c1d6e25676fed6a9d034ae218e branch ‘feature/perf_jobs_master2mesos’ of ssh://stash.bbpd.io/learn/jenkins
emambp:jenkins emacat.git/refs/heads/perfjobsmaster2mesos836eb8f427c090064fd922fd4ca7656975a4809aemambp:jenkinsema git fetch origin feature/perf_jobs_master2mesos
From ssh://stash.bbpd.io/learn/jenkins
* branch feature/perf_jobs_master2mesos -> FETCH_HEAD
emambp:jenkins ema$ cat .git/FETCH_HEAD
836eb8f427c090064fd922fd4ca7656975a4809a branch ‘feature/perf_jobs_master2mesos’ of ssh://stash.bbpd.io/learn/jenkins

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章