2011-12-14 16 views
13

Soy un novato en Git y tengo problemas para entender cómo usar Git. He estado usando CVS, pasando por una curva de aprendizaje para Git. Esto es lo que intentéCómo hacer git merge/pull correctamente: No ha concluido su fusión (MERGE_HEAD existe)

Ahora solo había cambiado dos archivos PromoServiceImpl.java y build.sql. Sin embargo, tiene problemas para fusionarse cambiado de la rama "producto".

Los archivos restantes que ve (como ApiServiceImpl.java, etc.) son cambios de otros usuarios, pero no estoy seguro de si la representación aquí sugiere que los he cambiado. ¿Prob se fusionó durante los comandos de extracción anteriores y ahora espera que los comprometa?

No importa lo que es el flujo de órdenes que sigo (incluso después de algunos búsqueda de Google) Veo el siguiente error:

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

Aquí está la secuencia de comandos Seguí y la salida (trataron de hacerlo bonito insertando nuevas líneas para que todos puedan leer). También este error vuelve incluso después de tomar cambios del repositorio de nuevo, así que estoy seguro de que estoy haciendo algo mal en lugar de un problema con 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

Un consejo rápido: simplemente olvídese de 'git pull'. No lo necesita, y es el La mejor manera de perderte en git. Puesto que se trata simplemente de una fetichización de git seguida de una fusión, utiliza ambas cosas. Y entre medias, puedes (¡ciertamente!) querer echar un vistazo a lo que realmente vas a fusionar. También quiero rebase en lugar de fusionar. En mi opinión, git pull es un atajo que puede ser muy confuso. –

+2

@ François sería muy cuidadoso con rebase - cambia el historial, lo cual no debería hacerse en términos de VCS, porque para eso es para preservar la historia. – valentinas

Respuesta

19

Hay un par de cosas pasando aquí. Ayuda a comprender qué sucede cuando emite varios comandos de Git.

El comando pull (como en git pull) results in un fetch seguida de una merge. Así que cuando usted hizo un pull

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

Git trató de tirar de cambios desde el valor por defecto a distancia repositorio

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

y fusionarlas en.

Auto-merging TryGitResources/build/build.sql 

Al hacerlo, se encontró un conflicto

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

Git maintains this 3 versions del archivo pendiente de una fusión - sus cambios, los cambios introducidos y el antecesor común. La versión extraída se almacena temporalmente en MERGE_HEAD.

Puede ver las diferencias con una invocación git diff. En este punto, debe solucionar los conflictos que Git no pudo resolver automáticamente. Una vez que lo haya solucionado, simplemente realice el habitual git add seguido de un git commit. Este proceso también se explica en la sección de ejemplos de la página man para el comando commit.

¡Oh! Y parece que tiene un archivo llamado Adding. Tenga en cuenta que el comando termina con git status

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

Esto sucede cuando se pregunta Git para rastrear un directorio (por ejemplo, cuando se hizo git init .). A partir de ese momento, Git supervisa los cambios en la ubicación especificada. Lo anterior dice: "Veo que ha agregado un archivo llamado Adding. No sé mucho más sobre él (no está rastreado)."Una vez que lo agregue, Git comienza a rastrear los cambios (puede decirle que ha cambiado con el tiempo).

Cuestiones relacionadas