git冲突

冲突:两个人在原有基础上相同位置添加了不同的代码,就叫冲突。如远程目录中有一个相同的文件a.txt,两个人拉取后,都在下一空白行(相同位置、添加)的代码,a修改完后推送到远程目录,b修改完后保存在本地仓库中,然后b使用pull命令拉取,会发生冲突。

修改:一个人在拉去的文件中最后一个字母修改为其他字母叫修改。添加一行内容也叫修改。


冲突解决:

git pull                                                                      
remote: Enumerating objects: 5, done.                                           
remote: Counting objects: 100% (5/5), done.                                     
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0                    
Unpacking objects: 100% (3/3), done.                                            
From https://github.com/diexiyan/test_conflict                                  
 * branch            master     -> FETCH_HEAD                                   
Auto-merging d.txt                                                              
CONFLICT (content): Merge conflict in d.txt                                     
Automatic merge failed; fix conflicts and then commit the result.               

打开冲突文件,按需要为文件内的冲突代码进行修改,再次提交到本地仓库、远程仓库,即可修改远程仓库内的文件。


未提交已修改文件到本地仓库就执行拉去操作:

git pull                                                                      
remote: Enumerating objects: 5, done.                                           
remote: Counting objects: 100% (5/5), done.                                     
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0                    
Unpacking objects: 100% (3/3), done.                                            
From https://github.com/diexiyan/test_conflict                                  
 * branch            master     -> FETCH_HEAD                                   
error: Your local changes to the following files would be overwritten by merge: 
        d.txt                                                                   
Please commit your changes or stash them before you merge.                      
Aborting                                                                        

提交文件到本地仓库再进行拉取即可。


新建的git目录推送到已有git目录的远程仓库中或者冲突文件没有处理正在进行推送:

error: failed to push some refs to 'https://github.com/diexiyan/project.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.      

检查冲突文件、新建工程重新推送git push url


已经拉取的文件没有对本地文件保存到本地仓库进行修改:

git pull                                                                      
From https://github.com/diexiyan/test_conflict                                  
 * branch            master     -> FETCH_HEAD                                   
Already up to date.

此时,属于修改内容·,可以使用push命令推送。可能是分支没有合并,需要合并到主分支,在进行提交


git 删除本地仓库

执行命令:rm -rf .git


总结:

远程目录的拉取与本地文件都与本地仓库有关,远程目录拉取后会保存在本地仓库里边。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值