简体   繁体   中英

fix conflicts for git merge branch to master

How do I merge this branch to master?

thufir@dur:~/NetBeansProjects$ 
thufir@dur:~/NetBeansProjects$ git clone -b 4.GUI_loading_messages_slowly git@github.com:THUFIR/USENET.git
Cloning into USENET...
remote: Counting objects: 3782, done.
remote: Compressing objects: 100% (1274/1274), done.
remote: Total 3782 (delta 1647), reused 3613 (delta 1478)
Receiving objects: 100% (3782/3782), 388.55 KiB | 100 KiB/s, done.
Resolving deltas: 100% (1647/1647), done.
thufir@dur:~/NetBeansProjects$ 
thufir@dur:~/NetBeansProjects$ cd USENET
thufir@dur:~/NetBeansProjects/USENET$ 
thufir@dur:~/NetBeansProjects/USENET$ git branch -a
* 4.GUI_loading_messages_slowly
  remotes/origin/1.FetchBean_CLI
  remotes/origin/2.some_GUI
  remotes/origin/3.messageId__string
  remotes/origin/4.GUI_loading_messages_slowly
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
thufir@dur:~/NetBeansProjects/USENET$ 
thufir@dur:~/NetBeansProjects/USENET$ git checkout -b master remotes/origin/master
Branch master set up to track remote branch master from origin.
Switched to a new branch 'master'
thufir@dur:~/NetBeansProjects/USENET$ 
thufir@dur:~/NetBeansProjects/USENET$ git branch
  4.GUI_loading_messages_slowly
* master
thufir@dur:~/NetBeansProjects/USENET$ 
thufir@dur:~/NetBeansProjects/USENET$ git diff master 4.GUI_loading_messages_slowly 
diff --git a/src/META-INF/persistence.xml b/src/META-INF/persistence.xml
index 252f563..3cebe3d 100644
--- a/src/META-INF/persistence.xml
+++ b/src/META-INF/persistence.xml
@@ -2,8 +2,8 @@
 <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http:/
   <persistence-unit name="USENETPU" transaction-type="RESOURCE_LOCAL">
     <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
-    <class>net.bounceme.dur.usenet.database.Article</class>
-    <class>net.bounceme.dur.usenet.database.Headers</class>
+    <class>net.bounceme.dur.usenet.model.Article</class>
+    <class>net.bounceme.dur.usenet.model.Newsgroup</class>
     <properties>
       <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/usenet
       <property name="javax.persistence.jdbc.password" value="password"/>
diff --git a/src/net/bounceme/dur/usenet/controller/ArticleNewsgroup.java b/src/net/bounceme
index b65737a..a9fadd2 100644
--- a/src/net/bounceme/dur/usenet/controller/ArticleNewsgroup.java
+++ b/src/net/bounceme/dur/usenet/controller/ArticleNewsgroup.java
@@ -5,8 +5,8 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 import javax.mail.Message;
 import javax.mail.MessagingException;
-import net.bounceme.dur.usenet.database.Article;
-import net.bounceme.dur.usenet.database.Headers;
+import net.bounceme.dur.usenet.model.Article;
+import net.bounceme.dur.usenet.model.Newsgroup;
 import net.bounceme.dur.usenet.model.Usenet;

thufir@dur:~/NetBeansProjects/USENET$ 
thufir@dur:~/NetBeansProjects/USENET$ git merge 4.GUI_loading_messages_slowly 
Auto-merging src/net/bounceme/dur/usenet/controller/Page.java
CONFLICT (content): Merge conflict in src/net/bounceme/dur/usenet/controller/Page.java
Auto-merging src/net/bounceme/dur/usenet/database/DatabaseUtils.java
CONFLICT (content): Merge conflict in src/net/bounceme/dur/usenet/database/DatabaseUtils.java
Auto-merging src/net/bounceme/dur/usenet/model/Usenet.java
CONFLICT (content): Merge conflict in src/net/bounceme/dur/usenet/model/Usenet.java
Automatic merge failed; fix conflicts and then commit the result.
thufir@dur:~/NetBeansProjects/USENET$ 
thufir@dur:~/NetBeansProjects/USENET$ 

It's not so much that I want to "fix" the conflicts but simply replace master with the branch. Perhaps rebase ?

git checkout master
git merge GUI_loading_messages_slowly
git commit
git push

You always switch to the branch, which you want to modify. So first checking out master is correct for your case. If your merge went wrong, you can with git reset "undo" your merge.

change to the branch you want merge and type.

git merge branchname

But you should really read the basics and the documentation at first.

Tutorials

The merge worked as advertised, but only after deleting the master branch:

thufir@dur:~/NetBeansProjects$ 
thufir@dur:~/NetBeansProjects$ git clone git@github.com:THUFIR/usenet.git
Cloning into usenet...
remote: Counting objects: 3750, done.
remote: Compressing objects: 100% (1263/1263), done.
remote: Total 3750 (delta 1630), reused 3585 (delta 1465)
Receiving objects: 100% (3750/3750), 385.93 KiB | 85 KiB/s, done.
Resolving deltas: 100% (1630/1630), done.
thufir@dur:~/NetBeansProjects$ 
thufir@dur:~/NetBeansProjects$ cd usenet/
thufir@dur:~/NetBeansProjects/usenet$ 
thufir@dur:~/NetBeansProjects/usenet$ git branch -a
* 4.GUI_loading_messages_slowly
  remotes/origin/1.FetchBean_CLI
  remotes/origin/2.some_GUI
  remotes/origin/3.messageId__string
  remotes/origin/4.GUI_loading_messages_slowly
  remotes/origin/HEAD -> origin/4.GUI_loading_messages_slowly
thufir@dur:~/NetBeansProjects/usenet$ 
thufir@dur:~/NetBeansProjects/usenet$ git branch master
thufir@dur:~/NetBeansProjects/usenet$ 
thufir@dur:~/NetBeansProjects/usenet$ git branch
* 4.GUI_loading_messages_slowly
  master
thufir@dur:~/NetBeansProjects/usenet$ 
thufir@dur:~/NetBeansProjects/usenet$ git checkout master
Switched to branch 'master'
thufir@dur:~/NetBeansProjects/usenet$ 
thufir@dur:~/NetBeansProjects/usenet$ git branch
  4.GUI_loading_messages_slowly
* master
thufir@dur:~/NetBeansProjects/usenet$ git branch -a
  4.GUI_loading_messages_slowly
* master
  remotes/origin/1.FetchBean_CLI
  remotes/origin/2.some_GUI
  remotes/origin/3.messageId__string
  remotes/origin/4.GUI_loading_messages_slowly
  remotes/origin/HEAD -> origin/4.GUI_loading_messages_slowly
thufir@dur:~/NetBeansProjects/usenet$ 
thufir@dur:~/NetBeansProjects/usenet$ git merge 4.GUI_loading_messages_slowly 
Already up-to-date.
thufir@dur:~/NetBeansProjects/usenet$ 
thufir@dur:~/NetBeansProjects/usenet$ git push origin master
Total 0 (delta 0), reused 0 (delta 0)
To git@github.com:THUFIR/usenet.git
 * [new branch]      master -> master
thufir@dur:~/NetBeansProjects/usenet$ 

The merge only worked because I first deleted the master branch, which seems a bit extreme, but there you are. Otherwise, I wasn't sure how to fix the conflicts without, as the fine manual suggests, editing the files so that they match. I just don't understand the point of a merge if you first have to manually edit things so that they match a different branch, it seems the there should be a prompt about that, not an error message.

With the proviso that you cannot delete the master branch with push origin :master on github without first changing the default branch, easy peasy. I find it somewhat aggravating that merge won't always merge automagically, and will sometimes barf back that there are conflicts. I don't see why merge can't return an advisory, and then ask "are you sure?" and then merge anyhow. In any event, I learned a (little) about git, in particular how to delete a branch.

I don't understand the meaning of Already up-to-date. , I mean, the origin on github certainly isn't up to date, so I wonder what's up to date. Presumably the local copy is up to date now, but why is it "already" up to date?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM