您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
38 把同一文件改成了不同的文...
发布时间:2020-08-01 17:17:06编辑:雪饮阅读()
首先客户端a和客户端b都full到最新的版本
然后a修改了文件名从index.html修改为indexa.html
并提交并push了
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/moral (test34)
$ git mv index.html indexa.html
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/moral (test34)
$ git commit -m "index.html to indexa.html"
[test34 ca74f10] index.html to indexa.html
1 file changed, 0 insertions(+), 0 deletions(-)
rename index.html => indexa.html (100%)
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/moral (test34)
$ git push
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 256 bytes | 256.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To github.com:xueyin220807/moral.git
8b45adf..ca74f10 test34 -> test34
那么此时b又修改index.html为indexb.html也push,我们发现b进行push时候又报错了
[root@localhost moral2]# git mv index.html indexb.html
[root@localhost moral2]# git commit -m "index.html to indexb.html"
[test34 50dd981] index.html to indexb.html
1 file changed, 0 insertions(+), 0 deletions(-)
rename index.html => indexb.html (100%)
[root@localhost moral2]# git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:
git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simple
See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)
To git@github.com:xueyin220807/moral.git
! [rejected] test34 -> test34 (fetch first)
error: failed to push some refs to 'git@github.com:xueyin220807/moral.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 merge the remote changes (e.g.,
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
那么b端尝试下pull的解决方案,发现冲突了
[root@localhost moral2]# git pull
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 2 (delta 1), reused 2 (delta 1), pack-reused 0
Unpacking objects: 100% (2/2), done.
From github.com:xueyin220807/moral
8b45adf..ca74f10 test34 -> origin/test34
CONFLICT (rename/rename): Rename "index.html"->"indexb.html" in branch "HEAD" rename "index.html"->"indexa.html" in "ca74f105c67c53dd941effef0366ce70b188997a"
Automatic merge failed; fix conflicts and then commit the result.
那么我们看看git status会给我们什么解决方案?
[root@localhost moral2]# git status
# On branch test34
# Your branch and 'origin/test34' have diverged,
# and have 1 and 1 different commit each, respectively.
# (use "git pull" to merge the remote branch into yours)
#
# You have unmerged paths.
# (fix conflicts and run "git commit")
#
# Unmerged paths:
# (use "git add/rm <file>..." as appropriate to mark resolution)
#
# both deleted: index.html
# added by them: indexa.html
# added by us: indexb.html
#
no changes added to commit (use "git add" and/or "git commit -a")
这里提示我们用git add或者git rm然后再commit,那么这里假定indexa.html是经过我和其他人员进行沟通后需要保留的则我们需要删除index.html、indexb.html并添加indexa.html则有
[root@localhost moral2]# git rm index.html
index.html: needs merge
rm 'index.html'
[root@localhost moral2]# git add indexa.html
[root@localhost moral2]# git rm indexb.html
indexb.html: needs merge
rm 'indexb.html'
然后我们就可以提交并push了
[root@localhost moral2]# git commit -m "rm index.html and add index.html and rm indexb.html"
[test34 60ef560] rm index.html and add index.html and rm indexb.html
[root@localhost moral2]# git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:
git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simple
See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)
Counting objects: 5, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 418 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To git@github.com:xueyin220807/moral.git
ca74f10..60ef560 test34 -> test34
关键字词:git,不同人,修改,同一文件,文件名