2013.12.31 ——— git学习之解决冲突

2013.12.31———git学习之解决冲突

同步代码的时候遇到了有冲突的情况,记一下,全部步骤如下:

git rebase –abort 放弃rebase,就是回到你执行git rebase那时的状态
git rebase --skip 直接用远程分支的取代当前分支的 也就是覆盖了本地的代码

第一次我解决错了

$ git fetch
$ git rebase
First, rewinding head to replay your work on top of it...
Applying: hot界面微调
Using index info to reconstruct a base tree...
M       /res/layout/hot_list_item.xml
<stdin>:11: trailing whitespace.
        android:spacing="0dp" />
warning: 1 line adds whitespace errors.
Falling back to patching base and 3-way merge...
Auto-merging /res/layout/hot_list_item.xml
CONFLICT (content): Merge conflict in /res/layout/hot_list_item.xml
Failed to merge in the changes.
Patch failed at 0001 hot界面微调
Warning: Your console font probably doesn't support Unicode. If you experience s
trange characters in the output, consider switching to a TrueType font such as L
ucida Console!

The copy of the patch that failed is found in:
   e:/Project/.git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

这个时候合并出错了,提示我有冲突,冲突是hot_list_item.xml

然后我解决了冲突,也就是删除了类似于svn的那些符号

$ git rebase --continue
PhoneKankan/res/layout/hot_list_item.xml: needs merge
You must edit all merge conflicts and then
mark them as resolved using git add

按照提示我执行了gitrebase--continue但是报错,根据提示可以知道没有暂存

$ git status
# rebase in progress; onto f81e6c1
# You are currently rebasing branch 'feature_3.0' on 'f81e6c1'.
#   (fix conflicts and then run "git rebase --continue")
#   (use "git rebase --skip" to skip this patch)
#   (use "git rebase --abort" to check out the original branch)
#
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   /res/layout/hot_carousel.xml
#       modified:   /src/com/phone/tab/hot/view/HotList
w.java
#
# Unmerged paths:
#   (use "git reset HEAD <file>..." to unstage)
#   (use "git add <file>..." to mark resolution)
#
#       both modified:      /res/layout/hot_list_item.xml
#

查看了一下状态,然后add

$ git add .

$ git commit --amend
[detached HEAD c896a87] 实现推荐页中点击全部时进入频道内容页的功能
 Author: 
 7 files changed, 110 insertions(+), 90 deletions(-)

Warning: Your console font probably doesn't support Unicode. If you experience
trange characters in the output, consider switching to a TrueType font such as
ucida Console!

$ git status
# rebase in progress; onto f81e6c1
# You are currently rebasing branch 'feature_3.0' on 'f81e6c1'.
#   (all conflicts fixed: run "git rebase --continue")
#
nothing to commit, working directory clean

$ git rebase --continue
Applying: hot界面微调
No changes - did you forget to use 'git add'?
If there is nothing left to stage, chances are that something else
already introduced the same changes; you might want to skip this patch.

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

这个错误的原因就是我提交了,其实只需要gitadd就行了,然后就可以continue,而我执行了gitcommit并且把我的更改“hot界面微调”提交到了别人的修改“实现推荐页中点击全部时进入频道内容页的功能”里面,所以我只好放弃rebase了

git rebase –abort

正确的过程如下:

$ git fetch

$ git rebase
First, rewinding head to replay your work on top of it...
Applying: hot界面微调
Using index info to reconstruct a base tree...
M       res/layout/hot_list_item.xml
<stdin>:11: trailing whitespace.
        android:spacing="0dp" />
warning: 1 line adds whitespace errors.
Falling back to patching base and 3-way merge...
Auto-merging res/layout/hot_list_item.xml
CONFLICT (content): Merge conflict in res/layout/hot_list_item.xml
Failed to merge in the changes.
Patch failed at 0001 hot界面微调
Warning: Your console font probably doesn't support Unicode. If you experience
trange characters in the output, consider switching to a TrueType font such as
ucida Console!

The copy of the patch that failed is found in:
   e:/Project/.git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

$ git status
# rebase in progress; onto f81e6c1
# You are currently rebasing branch 'feature_3.0' on 'f81e6c1'.
#   (fix conflicts and then run "git rebase --continue")
#   (use "git rebase --skip" to skip this patch)
#   (use "git rebase --abort" to check out the original branch)
#
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   res/layout/hot_carousel.xml
#       modified:   src/com/kankan/phone/tab/hot/view/HotListItemVi
w.java
#
# Unmerged paths:
#   (use "git reset HEAD <file>..." to unstage)
#   (use "git add <file>..." to mark resolution)
#
#       both modified:      res/layout/hot_list_item.xml
#

$ git add .

$ git status
# rebase in progress; onto f81e6c1
# You are currently rebasing branch 'feature_3.0' on 'f81e6c1'.
#   (all conflicts fixed: run "git rebase --continue")
#
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   /res/layout/hot_carousel.xml
#       modified:   /res/layout/hot_list_item.xml
#       modified:   /src/com/kankan/phone/tab/hot/view/HotListItemVi
w.java
#

$ git commit
Aborting commit due to empty commit message.

$ git rebase --continue
Applying: hot界面微调

相关推荐