GIT 4 冲突解决

无关文件

afunction1之后入库了feature2.xbfunction1之后本地增加了feature3.1,此时b入库会提示错误:

[smbtest@localhost b]$ git push

To ssh://[email protected]:7999/gpon/test.git

 ! [rejected]        master -> master (non-fast-forward)

error: failed to push some refs to 'ssh://[email protected]:7999/gpon/test.git'

hint: Updates were rejected because the tip of your current branch is behind

hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')

hint: before pushing again.

hint: See the 'Note about fast-forwards' in 'git push --help' for details.

此时需要重新pull 一次远端库,获取到远端库的修改

[smbtest@localhost b]$ git pull origin master

From ssh://sny-jira.ads.finisar.com:7999/gpon/test

 * branch            master     -> FETCH_HEAD

Merge made by the 'recursive' strategy.

 0 files changed

 create mode 100644 feature2.1

 create mode 100644 feature2.2

 create mode 100644 feature2.3

此时,可以看到log的变化(在feature 3.1之前增加了feature 2.xcommit log,之后增加了一条mergelog

[smbtest@localhost b]$ git log

commit 006871f55dbabe3eb2852c5011b555f4cbddcb8b

Merge: 50b4877 c4b214a

    Merge branch 'master' of ssh://sny-jira.ads.finisar.com:7999/gpon/test

 

commit 50b48770c13bac5b6e97088d6d071649f4d55b35

    feature 3.1

commit c4b214aff15850d17b386b10cf2cd5e855f27f33

feature 2.3

commit 7e42cf823c6efe22dee4382a847a744914572e35

    feature 2.2

commit cd342b2acc8bb7f4ca5f18900ea4526aa307618e

feature 2.1

最后再push

log上看,其实最后一条merge log属于一条冗余信息,我们当然知道应该要merge一下,如何避免这条冗余信息,可以参考git reset的使用。

相同文件

假设aa.txt增加了feature 4.1,已入到远端库,ba.txt增加feature 4.2,此时pull也会提示错误:

[smbtest@localhost b]$ git pull origin master

remote: Counting objects: 5, done.

remote: Compressing objects: 100% (3/3), done.

remote: Total 3 (delta 2), reused 0 (delta 0)

Unpacking objects: 100% (3/3), done.

From ssh://sny-jira.ads.finisar.com:7999/gpon/test

 * branch            master     -> FETCH_HEAD

Auto-merging a.txt

CONFLICT (content): Merge conflict in a.txt

Automatic merge failed; fix conflicts and then commit the result.

使用git status,可以看到自动merge失败的文件a.txt

[smbtest@localhost b]$ git status

# On branch master

# Unmerged paths:

#   (use "git add/rm <file>..." as appropriate to mark resolution)

#

#       both modified:      a.txt

#

no changes added to commit (use "git add" and/or "git commit -a")

使用git diff,可以查看具体的差异,03ef4d19eb8c2ad7b93ce7e486f6a01ab7e0856d是远端库的commit id

[smbtest@localhost b]$ git diff a.txt

diff --cc a.txt

index 7e6411a,a32e92b..0000000

--- a/a.txt

+++ b/a.txt

@@@ -7,4 -7,4 +7,8 @@@ function

     feature 1.3

 

  function 4

++<<<<<<< HEAD

 +   feature 4.2

++=======

+    feature 4.1

++>>>>>>> 03ef4d19eb8c2ad7b93ce7e486f6a01ab7e0856d

根据需要修改a.txtgit addgit commit后,push

你可能感兴趣的:(git,冲突,merge)