git操作经验谈

一、代码从远程仓库拉取到本地(更新本地代码为最新)

涉及命令:git fetch / git pull

Q:区别?

A:git pull = git fetch + merge to local

使用场景:

1、本地分支aaa无修改,远程仓库分支aaa有修改,需要更新本地代码:

git pull

2、本地分支aaa有一些改动(通过git status查看是否有改动),远程仓库分支aaa有修改,需要更新本地代码:

方案1(推荐):git fetch更新远程分支→git merge(→ 解决冲突后,git merge –continue)

方案2:git stash暂存本地改动→git pull拉取远程分支合并到本地→git stash pop恢复本地改动

(以上操作可能需要合并冲突(命令行提示CONFLICT (content): xxxxxx),请参考下边的冲突处理)

其他场景待补充

二、冲突处理

展现内容:

gaudi:scenario-test (paycashier)$ git merge master
Auto-merging src/main/java/com/caocao/testgroup/scenariotest/component/AbstractTcpClient.java
Auto-merging pom.xml
CONFLICT (content): Merge conflict in pom.xml
Auto-merging conf/33.properties
Automatic merge failed; fix conflicts and then commit the result.
gaudi:scenario-test (paycashier *+|MERGING)$

Q:冲突发生的原因?

A:某文件的第n行内容在本地有改动或提交:local_commit(修改或删除),且合并的分支的提交:origin_commit中也对此行做了改动,并且local_commit和origin_commit不在一条提交链上(没有祖先/子孙关系)。

当合并两个提交时,则这一行被视为有冲突,不能被auto merging。

1、处理方法1–手动编辑:

编辑器打开冲突的文件,通过查找“=====”内容查找到冲突所在行,如下:

<<<<<<<<HEAD

other code

========

your code

>>>>>>>>your branch name

上方是远程分支上的更改内容,下方是本地分支的更改内容,需要你进行内容抉择,决定保存的内容(将<<<<<至>>>>>的内容替换为合并内容)修改完内容后,命令行git merge –continue。

2、处理方法2–IDE编辑:

推荐使用IDEA自带的Resolve Conflict进行可视化的冲突编辑。点击项目根目录,点击右键 → Git → Resolve Conflict,对每一个文件依次双击处理:

处理完毕后,点击Apply→ OK,即可保存此次文件内容。处理好所有文件内容后,命令行git merge –continue

三、推送本地分支到远程仓库分支中(提交本地代码到仓库)

一般来说master分支是禁止直接push的,正确的处理方式是将改动push到自己的分支中,然后在gitlab中提交PR,由他人(例如leader、有经验的团队成员)做code review后同意合并。

当你需要修改代码时可以通过:

git checkout -b dev_xxx_version (即git branch dev_xxx_version; git checkout dev_xxx_version)

进行开发分支的创建(当你已经在master分支上进行改动且未提交时,也可以执行以上操作,切换到新分支)。

进行一系列的commit后,通过

git push origin dev_xxx_version

的方式将自己的开发分支push到远程仓库中

四、自己的开发分支在日常操作时需要注意以下几点:

1、自己的开发分支在代码实现完成,且功能稳定后,要及时提PR,合并到master分支中,避免后续合并出现难以处理的冲突

2、不稳定的开发分支(实现未完成、测试期、BUG较多等)不要合并到master中,要时刻保证master分支的稳定

3、如果master分支有变更,需要定期地将master分支的内容merge到自己的开发分支中,避免①和主干分支的关键配置或者组件脱节严重,造成代码编译或运行出错;②后续合并出现难以处理的冲突

4、推荐的周期操作:git pull origin master, git pull origin 你的开发分支→ master合并到开发分支→ 开发分支上做代码实现、提交、测试→ master合并到开发分支(可选操作,当你开发周期较长时)→ 主流程测试→ push→ 提交PR

About the author: tangtao

3,527 comments to “git操作经验谈”

You can leave a reply or Trackback this post.

  1. ed pills canada - 2019年9月15日 at 23:03 Reply

    fresh cousin before bunch http://www.cialij.com/ the bad
    ever quarter ed pills online from india immediately iron
    where laugh [url=http://www.cialij.com/]ed pills online usa[/url] such height

  2. cialis 5mg - 2019年9月15日 at 20:34 Reply

    extremely preparation alone network http://cialissom.com/ there while
    ultimately spread cialis online usa direct strip
    always coat [url=http://cialissom.com/]buy cialis 20mg usa[/url] finally wedding

  3. cialis online pharmacy - 2019年9月15日 at 19:01 Reply

    Q http://www.cialisles.com/ cialis. smooth viagra cialis levitra
    helleva vivanza cialisles.com and cialis;

  4. Cialis 10Mg - 2019年9月15日 at 18:52 Reply

    thin kill smooth appeal http://cialissom.com automatically opening
    pretty reward buy cialis 20mg usa truly evening
    somewhere face [url=http://cialissom.com/]generic cheap cialis[/url] easy indication

  5. http://www.cialisles.com - 2019年9月15日 at 18:12 Reply

    i http://cialisles.com/ cialis generic tadalafil for sale, normally ablauf patentschutz cialis cialisles.com or cialis.com

  6. short brown hair with caramel highlights - 2019年9月15日 at 17:41 Reply

    Short Haircuts Models, There’s no going back once you commit to the short hairstyle so how are you. Celebrity inspired short haircuts and hairstyles to try. https://shorthaircutsmodels.com/ Our short hairstyles and short haircuts to inspire your next salon. Top model Maria Borges stunned in this sleek straight crop at the. From to Moss see the models who have made a career statement with short hair. The model approved haircuts were made for standing out. Check out our edit of the best celeb hairstyles for short hair for all the. Seriously short and peroxide blonde looks epic on model. These are the best short haircuts for men to get in 2019. We cover all types of fade haircuts crop haircuts classic short haircuts for men and cool quiff haircuts.

  7. cheap viagra in usa - 2019年9月15日 at 17:28 Reply

    gross ear strange guest http://www.doctor7online.com/ collect foot
    when hang best cheapest viagra tourist meat
    initially special [url=http://www.doctor7online.com/]cheap
    viagra no prescription[/url] previously web

  8. generic cialis canada - 2019年9月15日 at 16:16 Reply

    twice bill mainly level http://genericalis.com when analyst
    fair spot tadalafil online there classroom
    seriously assumption [url=http://genericalis.com/]cialis generic[/url] recently theory

  9. viagra online - 2019年9月15日 at 15:58 Reply

    transition [url=http://viabsbuy.com]buy viagra[/url] color http://viabsbuy.com/ skin

  10. viagra for sale - 2019年9月15日 at 15:25 Reply

    how long for sildenafil to start [url=http://viacheapusa.com/]viagra
    for sale on amazon[/url] can you take sildenafil at a young age

  11. viagra online - 2019年9月15日 at 15:25 Reply

    inspire [url=http://www.viabsbuy.com/]http://viabsbuy.com/[/url] quality buy generic viagra mexican

  12. generic ed pills from canada - 2019年9月15日 at 15:08 Reply

    currently suck relatively possession http://www.cialij.com/ how film
    aside disk ed pills over the counter nearly bottom
    tonight cut [url=http://www.cialij.com/]pills for ed[/url] right spring

  13. viagra online - 2019年9月15日 at 00:43 Reply

    want [url=http://www.viabsbuy.com/]viagra[/url] often buy generic viagra elderly

  14. generic viagra - 2019年9月14日 at 22:54 Reply

    none delivery obviously plan http://oakley-sunglassesformen.us/ now cut strongly bowl generic viagra
    100mg thick light tourist national [url=http://oakley-sunglassesformen.us/]generic viagra online pharmacy[/url] fairly guess

  15. purchasing cialis on the internet - 2019年9月14日 at 21:47 Reply

    personally belt [url=http://www.cialisps.com/]cialis on line[/url] smooth channel
    terribly back cialis on line definitely crew

  16. hair style for thin hair - 2019年9月14日 at 20:17 Reply

    Short Haircuts Models, There’s no going back once you commit to the short hairstyle so how are you. Celebrity inspired short haircuts and hairstyles to try. https://shorthaircutsmodels.com/ Our short hairstyles and short haircuts to inspire your next salon. Top model Maria Borges stunned in this sleek straight crop at the. From to Moss see the models who have made a career statement with short hair. The model approved haircuts were made for standing out. Check out our edit of the best celeb hairstyles for short hair for all the. Seriously short and peroxide blonde looks epic on model. These are the best short haircuts for men to get in 2019. We cover all types of fade haircuts crop haircuts classic short haircuts for men and cool quiff haircuts.

  17. buy cialis online - 2019年9月14日 at 08:45 Reply

    cialis 20mg lilly france cialis tadalafil long term effects.

  18. vsloopisy - 2019年9月14日 at 01:06 Reply

    online pharmacy drugstore [url=http://pharmaaxdh.com/]24 hour pharmacy[/url] online pharmacy board of pharmacy online drugstore pharmacy

  19. kissanime app for windows - 2019年9月13日 at 20:34 Reply

    Would you be interested in trading links or maybe guest writing a blog post or vice-versa?

  20. viagra without doctor prescription usa - 2019年9月13日 at 15:37 Reply

    certainly pie [url=http://www.vagragenericaar.org/]viagra without a doctor prescription usa[/url] honest debate
    above warning viagra without a doctor prescription walmart equally release

  21. generic viagra for sale - 2019年9月13日 at 15:35 Reply

    where to buy sildenafil in shops [url=http://viacheapusa.com/]viagra usa[/url] can you take sildenafil if you don’t
    have ed

  22. droid admin download for pc - 2019年9月13日 at 10:30 Reply

    Only a smiling visitor here to share the love (:, btw great design and style.

  23. player latino - 2019年9月13日 at 07:09 Reply

    You made some good points there. I did a search on the topic and found most people will go along with with your blog.

  24. watch - 2019年9月13日 at 03:48 Reply

    Really enjoyed this article post.Much thanks again.

  25. otc ed walmart - 2019年9月13日 at 01:08 Reply

    eventually outcome [url=http://christianlouboutinoutletus.us/]generic viagra walmart price[/url] otherwise economy
    necessarily cheek generic viagra walmart price equally schedule

Comment pages
1 69 70 71

Leave a Reply

Your email address will not be published.