大数据全系列 教程
1869个小节阅读:467.6k
408考研
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
####4.3.5.2 解决冲突
冲突演示:
gitee上修改UserVo.java
xxxxxxxxxx
public class UserVo{
private String name;
private int age;
public void setName(String name){
this.name = name;
}
}
本地修改
xxxxxxxxxx
public class UserVo{
private String name;
private int age;
public void setAge(int age){
this.age = age;
}
}
本地上添加到缓存区
xxxxxxxxxx
$ git add UserVo.java
Administrator@SC-201911261404 MINGW64 /d/GitSpace/second_git_repos/first (master)
本地上提交到本地仓库
xxxxxxxxxx
$ git commit -m "local commit a" UserVo.java
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
Administrator@SC-201911261404 MINGW64 /d/GitSpace/second_git_repos/first (master)
本地push到gitee
xxxxxxxxxx
$ git push https://gitee.com/gtjinxf/first.git master
To https://gitee.com/gtjinxf/first.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://gitee.com/gtjinxf/first.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
#出现了版本冲突的问题。
从远程库上pull到本地
xxxxxxxxxx
$ git pull https://gitee.com/gtjinxf/first.git master
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 345 bytes | 2.00 KiB/s, done.
From https://gitee.com/gtjinxf/first
* branch master -> FETCH_HEAD
Auto-merging UserVo.java
CONFLICT (content): Merge conflict in UserVo.java
Automatic merge failed; fix conflicts and then commit the result.
Administrator@SC-201911261404 MINGW64 /d/GitSpace/second_git_repos/first (master|MERGING)
$ git diff UserVo.java
diff --cc UserVo.java
index 478afc0,a62839c..0000000
--- a/UserVo.java
+++ b/UserVo.java
@@@ -1,7 -1,7 +1,13 @@@
public class UserVo{
private String name;
private int age;
++<<<<<<< HEAD #本地仓库中的修改
+ public void setAge(int age){
+ this.age = age;
+ }
++======= #gitee远程仓库中修改后的内容
+ public void setName(String name){
+ this.name = name;
+ }
++>>>>>>> 016db7279eb2bd93e76015ee3cabd75245cbef7c
}
Administrator@SC-201911261404 MINGW64 /d/GitSpace/second_git_repos/first (master|MERGING)
手动修改本地仓库中UserVo.java文件
xxxxxxxxxx
public class UserVo{
private String name;
private int age;
public void setName(String name){
this.name = name;
}
public void setAge(int age){
this.age = age;
}
}
然后再次提交
xxxxxxxxxx
$ git add UserVo.java
Administrator@SC-201911261404 MINGW64 /d/GitSpace/second_git_repos/first (master|MERGING)
$ git commit -m "local commit a3" UserVo.java
fatal: cannot do a partial commit during a merge.
Administrator@SC-201911261404 MINGW64 /d/GitSpace/second_git_repos/first (master|MERGING)
$ git commit -m "local commit a3"
[master 0e88013] local commit a3
Administrator@SC-201911261404 MINGW64 /d/GitSpace/second_git_repos/first (master)
$ git push https://gitee.com/gtjinxf/first.git master
Enumerating objects: 10, done.
Counting objects: 100% (10/10), done.
Delta compression using up to 8 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 670 bytes | 670.00 KiB/s, done.
Total 6 (delta 3), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.1]
To https://gitee.com/gtjinxf/first.git
016db72..0e88013 master -> master
要点