2011-12-14 8 views
13

Tôi là một newbie cho Git và gặp khó khăn trong việc hiểu cách sử dụng Git. Tôi đã sử dụng CVS để trải qua một số đường cong học tập cho Git. Đây là tất cả những gì tôi đã thửLàm thế nào để thực hiện git merge/pull một cách chính xác: Bạn chưa kết luận hợp nhất của bạn (MERGE_HEAD tồn tại)

Bây giờ tôi đã chỉ thay đổi hai tệp PromoServiceImpl.java và build.sql. Tuy nhiên gặp sự cố khi hợp nhất đã thay đổi từ chi nhánh "sản phẩm".

Các tệp còn lại mà bạn thấy (như ApiServiceImpl.java, v.v) là những thay đổi từ những người dùng khác nhưng tôi không chắc liệu biểu diễn ở đây có gợi ý rằng tôi đã thay đổi chúng hay không. Prob nó đã được sáp nhập trong các lệnh kéo trước đó và bây giờ nó hy vọng tôi cam kết chúng?

Không có vấn đề gì là dòng chảy của lệnh tôi làm theo (ngay cả sau khi một số tìm kiếm Google) mà tôi thấy được lỗi sau:

You have not concluded your merge (MERGE_HEAD exists) Please, commit your changes before you can merge.

Đây là chuỗi các lệnh Tôi đi theo và đầu ra (cố gắng để làm cho nó khá bằng cách chèn các dòng mới để mọi người đọc). Ngoài ra lỗi này trở lại ngay cả sau khi thay đổi từ kho lưu trữ afresh vì vậy tôi chắc chắn tôi đang làm một cái gì đó sai hơn là một số vấn đề với git.

[email protected]:~/git/TryGit$ gs 
# On branch product 
# Your branch is ahead of 'origin/product' by 1 commit. 
# 
# Changes not staged for commit: 
# (use "git add <file>..." to update what will be committed) 
# (use "git checkout -- <file>..." to discard changes in working directory) 
# 
# modified: TryGitServices/src/main/java/com/TryGit/services/promo/impl/PromoServiceImpl.java 
# 
# Untracked files: 
# (use "git add <file>..." to include in what will be committed) 
# 
# Adding 
no changes added to commit (use "git add" and/or "git commit -a") 


[email protected]:~/git/TryGit$ git pull origin product 
From ssh://192.168.2.251/TryGit 
* branch   product -> FETCH_HEAD 
Auto-merging TryGitResources/build/build.sql 
CONFLICT (content): Merge conflict in TryGitResources/build/build.sql 
Automatic merge failed; fix conflicts and then commit the result. 


[email protected]:~/git/TryGit$ gs 
# On branch product 
# Your branch is ahead of 'origin/product' by 1 commit. 
# 
# Changes to be committed: 
# 
# modified: TryGitCore/src/main/java/com/TryGit/core/api/binding.xml 
# modified: TryGitServices/src/main/java/com/TryGit/services/api/impl/ApiServiceImpl.java 
# modified: TryGitServices/src/main/java/com/TryGit/services/common/impl/StartupServiceImpl.java 
# modified: TryGitWeb/src/main/webapp/WEB-INF/wsdl/TryGit.wsdl 
# modified: TryGitWeb/src/main/webapp/static/css/TryGit/homeDeal.css 
# modified: TryGitWeb/src/main/webapp/static/css/TryGit/TryGit.css 
# modified: TryGitWeb/src/main/webapp/static/img/TryGit/sprite/TryGit.png 
# modified: TryGitWeb/src/main/webapp/views/admin/createPromoCode.jsp 
# modified: TryGitWeb/src/main/webapp/views/admin/product/productAdmin.jsp 
# modified: TryGitWeb/src/main/webapp/views/deal/homePage.jsp 

# 
# Unmerged paths: 
# (use "git add/rm <file>..." as appropriate to mark resolution) 
# 
# both modified:  TryGitResources/build/build.sql 
# 
# Changes not staged for commit: 
# (use "git add <file>..." to update what will be committed) 
# (use "git checkout -- <file>..." to discard changes in working directory) 
# 
# modified: TryGitServices/src/main/java/com/TryGit/services/promo/impl/PromoServiceImpl.java 
# 
# Untracked files: 
# (use "git add <file>..." to include in what will be committed) 
# 
# Adding 


[email protected]:~/git/TryGit$ git reset TryGitResources/build/build.sql 
Unstaged changes after reset: 
M TryGitResources/build/build.sql 
M TryGitServices/src/main/java/com/TryGit/services/promo/impl/PromoServiceImpl.java 
[email protected]:~/git/TryGit$ gs 
# On branch product 
# Your branch is ahead of 'origin/product' by 1 commit. 
# 
# Changes to be committed: 
# 
# modified: TryGitCore/src/main/java/com/TryGit/core/api/binding.xml 
# modified: TryGitResources/build/build.sql 
# modified: TryGitServices/src/main/java/com/TryGit/services/api/impl/ApiServiceImpl.java 
# modified: TryGitServices/src/main/java/com/TryGit/services/common/impl/StartupServiceImpl.java 
# modified: TryGitWeb/src/main/webapp/WEB-INF/wsdl/TryGit.wsdl 
# modified: TryGitWeb/src/main/webapp/static/css/TryGit/homeDeal.css 
# modified: TryGitWeb/src/main/webapp/static/css/TryGit/TryGit.css 
# modified: TryGitWeb/src/main/webapp/static/img/TryGit/sprite/TryGit.png 
# modified: TryGitWeb/src/main/webapp/views/admin/createPromoCode.jsp 
# modified: TryGitWeb/src/main/webapp/views/admin/product/productAdmin.jsp 
# modified: TryGitWeb/src/main/webapp/views/deal/homePage.jsp 
# 
# Changes not staged for commit: 
# (use "git add <file>..." to update what will be committed) 
# (use "git checkout -- <file>..." to discard changes in working directory) 
# 
# modified: TryGitResources/build/build.sql 
# modified: TryGitServices/src/main/java/com/TryGit/services/promo/impl/PromoServiceImpl.java 
# 
# Untracked files: 
# (use "git add <file>..." to include in what will be committed) 
# 
# Adding 


[email protected]:~/git/TryGit$ git stash 
Saved working directory and index state WIP on product: b8bb080 changing build.sql for RBT task 
HEAD is now at b8bb080 changing build.sql for RBT task 


[email protected]:~/git/TryGit$ gs 
# On branch product 
# Your branch is ahead of 'origin/product' by 1 commit. 
# 
# Untracked files: 
# (use "git add <file>..." to include in what will be committed) 
# 
# Adding 
nothing added to commit but untracked files present (use "git add" to track) 


[email protected]:~/git/TryGit$ git reset Adding 


[email protected]:~/git/TryGit$ git reset Adding 


[email protected]:~/git/TryGit$ gs 
# On branch product 
# Your branch is ahead of 'origin/product' by 1 commit. 
# 
# Untracked files: 
# (use "git add <file>..." to include in what will be committed) 
# 
# Adding 
nothing added to commit but untracked files present (use "git add" to track) 

[email protected]:~/git/TryGit$ git rm Adding 
fatal: pathspec 'Adding' did not match any files 

[email protected]:~/git/TryGit$ man git rm 

[email protected]:~/git/TryGit$ git rm Adding 
fatal: pathspec 'Adding' did not match any files 

[email protected]:~/git/TryGit$ gs 
# On branch product 
# Your branch is ahead of 'origin/product' by 1 commit. 
# 
# Untracked files: 
# (use "git add <file>..." to include in what will be committed) 
# 
# Adding 
nothing added to commit but untracked files present (use "git add" to track) 

[email protected]:~/git/TryGit$ git pull origin product 
remote: Counting objects: 566, done. 
remote: Compressing objects: 100% (316/316), done. 
remote: Total 386 (delta 207), reused 0 (delta 0) 
Receiving objects: 100% (386/386), 203.81 KiB, done. 
Resolving deltas: 100% (207/207), completed with 56 local objects. 
From ssh://192.168.2.251/TryGit 
* branch   product -> FETCH_HEAD 
Auto-merging TryGitResources/build/build.sql 
CONFLICT (content): Merge conflict in TryGitResources/build/build.sql 
Automatic merge failed; fix conflicts and then commit the result. 

[email protected]:~/git/TryGit$ git pull origin product 
M TryGitCore/src/main/java/com/TryGit/core/api/binding.xml 
U TryGitResources/build/build.sql 
M TryGitServices/src/main/java/com/TryGit/services/api/impl/ApiServiceImpl.java 
M TryGitServices/src/main/java/com/TryGit/services/common/impl/StartupServiceImpl.java 
M TryGitWeb/src/main/webapp/WEB-INF/wsdl/TryGit.wsdl 
M TryGitWeb/src/main/webapp/static/css/TryGit/homeDeal.css 
M TryGitWeb/src/main/webapp/static/css/TryGit/TryGit.css 
M TryGitWeb/src/main/webapp/static/img/TryGit/sprite/TryGit.png 
M TryGitWeb/src/main/webapp/views/admin/createPromoCode.jsp 
M TryGitWeb/src/main/webapp/views/admin/product/productAdmin.jsp 
M TryGitWeb/src/main/webapp/views/deal/homePage.jsp 
Pull is not possible because you have unmerged files. 
Please, fix them up in the work tree, and then use 'git add/rm <file>' 
as appropriate to mark resolution, or use 'git commit -a'. 

[email protected]:~/git/TryGit$ git add TryGitResources/build/build.sql 
[email protected]:~/git/TryGit$ git pull origin product 
You have not concluded your merge (MERGE_HEAD exists). 
Please, commit your changes before you can merge. 
[email protected]:~/git/TryGit$ gs 
# On branch product 
# Your branch is ahead of 'origin/product' by 1 commit. 
# 
# Changes to be committed: 
# 
# modified: TryGitCore/src/main/java/com/TryGit/core/api/binding.xml 
# modified: TryGitResources/build/build.sql 
# modified: TryGitServices/src/main/java/com/TryGit/services/api/impl/ApiServiceImpl.java 
# modified: TryGitServices/src/main/java/com/TryGit/services/common/impl/StartupServiceImpl.java 
# modified: TryGitWeb/src/main/webapp/WEB-INF/wsdl/TryGit.wsdl 
# modified: TryGitWeb/src/main/webapp/static/css/TryGit/homeDeal.css 
# modified: TryGitWeb/src/main/webapp/static/css/TryGit/TryGit.css 
# modified: TryGitWeb/src/main/webapp/static/img/TryGit/sprite/TryGit.png 
# modified: TryGitWeb/src/main/webapp/views/admin/createPromoCode.jsp 
# modified: TryGitWeb/src/main/webapp/views/admin/product/productAdmin.jsp 
# modified: TryGitWeb/src/main/webapp/views/deal/homePage.jsp 

# 
# Untracked files: 
# (use "git add <file>..." to include in what will be committed) 
# 
# Adding 

[email protected]:~/git/TryGit$ git pull origin product 
You have not concluded your merge (MERGE_HEAD exists). 
Please, commit your changes before you can merge. 

[email protected]:~/git/TryGit$ 
+2

Lời khuyên nhanh: chỉ cần quên 'git pull'. Bạn không cần nó, và đó là Cách tốt nhất để bị lạc trong git Vì nó chỉ đơn thuần là git fetch, sau đó là merge, sử dụng cả hai thứ này! Và inbetween, bạn có thể (chắc chắn!) muốn xem cái bạn đang thực sự hợp nhất. Theo tôi, git pull là một phím tắt có thể rất khó hiểu –

+2

@ François tôi sẽ rất cẩn thận với việc rebase - nó thay đổi lịch sử, không nên thực hiện theo VCS, bởi vì đó là những gì nó cho - để bảo tồn lịch sử. – valentinas

Trả lời

19

Có một vài điều đang diễn ra tại đây. Nó giúp để hiểu những gì sẽ xảy ra khi bạn phát hành các lệnh Git khác nhau.

Lệnh pull (như trong git pull) results in a fetch theo sau là merge. Vì vậy, khi bạn đã làm một pull

[email protected]:~/git/TryGit$ git pull origin product 

Git cố gắng để kéo những thay đổi từ mặc định từ xa kho

From ssh://192.168.2.251/TryGit 
* branch   product -> FETCH_HEAD 

và hợp nhất chúng vào.

Auto-merging TryGitResources/build/build.sql 

Bằng cách đó nó gặp phải một cuộc xung đột

CONFLICT (content): Merge conflict in TryGitResources/build/build.sql 
Automatic merge failed; fix conflicts and then commit the result. 

Git maintains this 3 versions của tệp đang chờ hợp nhất - các thay đổi của bạn, thay đổi được kéo vào và tổ tiên chung. Phiên bản được kéo vào tạm thời được lưu trữ trong MERGE_HEAD.

Bạn có thể thấy sự khác biệt với yêu cầu git diff. Tại thời điểm này, bạn cần khắc phục các xung đột mà Git không thể tự động giải quyết. Một khi bạn đã sửa nó chỉ đơn giản là thực hiện các thông thường git add theo sau là git commit. Quá trình này cũng được giải thích trong phần ví dụ của trang hướng dẫn sử dụng cho lệnh commit.

Oh! Và có vẻ như bạn có một tệp được gọi là Adding. Lưu ý rằng lệnh git status kết thúc với

# Untracked files: 
# (use "git add <file>..." to include in what will be committed) 
# 
# Adding 

Điều này xảy ra khi bạn hỏi Git để theo dõi một thư mục (chẳng hạn như khi bạn đã làm git init .). Từ đó trên màn hình Git thay đổi ở vị trí đã chỉ định. Ở trên là nói rằng "Tôi thấy rằng bạn đã thêm một tập tin gọi là Thêm. Tôi không biết nhiều hơn về nó (nó là untracked)."Khi bạn thêm nó, Git bắt đầu theo dõi các thay đổi (có thể cho bạn biết những gì đã thay đổi theo thời gian).