Proper push to modified remote repository workflow with egit - eclipse

I am trying to jump over my shadow and finally learn git at a basic level. Like countless beginners before me I ran into the dreaded "egit rejected non-fast-forward" error when trying to push after merging in the remote changes and "marking as merged".
It seems like I already found a solution for this problem, but it is cumbersome and not compatible with the eclipse compare editor. I do it like this:
Push my changes - causes the "egit rejected non-fast-forward" error
Pull changes - The compare editor now contains <, = and > markers. I can't comfortably compare and push around changes as the right side of the compare editor is empty and the left contains my changes and the remote conflicting changes above each other, which is pretty useless.
Painfully pick the parts I want by manually editing the text.
Am I using egit the right way?
Is there a way to properly use both sides of the compare editor?
I want to see my version which will be pushed and it's differences to the current remote version at all times during the merge.

I'm not familiar with egit, but it sounds like you are dealing with a merge conflict. Am I right in assuming that someone else also has push access to the branch you're working on? What likely happened is they pushed new changes to the branch, which is what is causing the rejection. And by pulling, you're trying to merge in some conflicting changes that you have to resolve. Here is a better explanation of the same problem.
The bad news is that merge conflicts always have to be resolved manually. The good news is that it looks like egit provides a merge tool for resolving these conflicts. This egit wiki page might help you find the comparison tool that you're looking for. Basically, just select the file that has conflicts and then select Team > Merge Tool
.
If that doesn't work, you can always confidently resolve merge conflicts just by using the git merge markers (<, >, and =). Read this for a detailed explanation of how those are used in Git. Basically, anything below <<< and above === will be your changes. The code below === and above >>> will be their changes. And you either have to pick which side you want, or you can customize it even further. by deleting everything and re-writing the code yourself.
Here's an example. This is something you might see when resolving a merge conflict. The top show you the commit at your local HEAD, your version of the commit. And the bottom, below the === shows the commit at origin/master, the version you just pulled in.
<<<<<< HEAD:test.html
<h1>This is my version</h1>
======
This is their version
>>>>>> origin/master:test.html
To keep only your version, you could just replace that entire block with this. It's like the arrows and equal signs are giving you a choice. Do you want the top (yours), or the bottom (theirs)?
<h1>This is my version</h1>
Alternatively, maybe you want a combination of both. Here, you would be keeping your <h1> html tag, but using their text.
<h1>This is their version</h1>
I hope this helps you feel more comfortable with resolving merge conflicts. If you want to learn more about Git, I always recommend git-scm.

Related

What is the downside to managing a repository with multiple heads?

I have a project with a single branch, default. I have been iterating on this single named branch for some time now and I have been using tags to mark version number milestones.
The project's source code changed quite a bit between tags 1.0.7 and 1.1.0 (current). However, there are some users on 1.0.7 that need a bug fix. So I checked out the source, updated to tag 1.0.7, implemented a fix and committed. That was tagged 1.0.8, and will probably be the last commit on the 1.0.x line.
I now have two heads on the default branch. I expected that. But when I tried to push to our BitBucket account, I received a warning from hg: "push creates new remote head". Reading up on this message, I get a lot of answers explaining why the message is there and for most people the answer is just to merge. However, I don't think I want that in this case. The two branches aren't compatible.
It looks like I can just use the -f option to force push the new head to the remote repository, however this seems to be discouraged both by hg help and various posts on the web without much explanation as to why. So what is the downside to doing this? It seems as though I can still update to whatever tags/revisions I want to continue working on. If I push that head to the BitBucket account, will I be shooting myself in the foot in some way?
Having multiple heads is perfectly fine.
If there are several heads and there's little indication as to their purpose, it may be difficult for others to see where they should continue and what is the head which contains the newest developments, e.g. which gains new features.
However by using the tags on the branch with clear versioning like you do, that problem doesn't exist either.
There's one small catch though: Mercurial will, upon clone, update to the newest commit in the default branch - e.g. the head which received the last commit. If that's the 1.0.x head of yours, that might be unfortunate. However you can fix this, by attaching the special '#' bookmark to the mainline or development head. Mercurial will always update to the head which bears that bookmark, if it is present - irrespective which head has the newest commit.

Eclipse Git Repository Branch Hash not updating

I been trying to follow this tutorial on using Eclipse and GITHUB when multiple people are writing within the same project using branches. I believe I understand everything and how its working.. HOWEVER.. my hash isn't updating like the video is showing on local branches.
https://www.youtube.com/watch?v=KfeqnernMmE
If you look at minute 3:50 - 3:60 you will see him do a COMMIT and it will then update on the local branch and generates a new HASH etc...(text in grey next to ChangeDefaults in the video) My Eclipse won't freaking do this. I make a change exactly like he does, I do a commit, but my Hash's and comment text (all the text in GREY) don't update or change at all. They same the exact same as it was before and I'm not seeing any onscreen errors or anything.
What am I missing?
Apparently there were 2 things I was doing wrong.
1) I wasn't using the correct Repository when I was modifying things. I had the wrong "Project" open.
2) I was missing an update and had to update my GIT inside my eclipse.

Is there any way to merge in a visual merge tool on windows that simultaneously shows annotations?

I am using Mercurial, but I imagine that any merge tool that is aware of the version control system below it could do several things that a merge tool which is not aware of the version control system and only sees two "files" in two different folders, could never do.
I have been using KDIFF3, and recently tried BeyondCompare, and neither of them will do this, at least not that I could figure out.
What I want to do is best shown in this picture, an annotation column and perhaps even ability to open other windows from those annotation columns so I could browse specific versions of specific files to see context when trying to do a merge.
In the image here, I am showing a two way merge, but the same applies for a three way merge. To the right or to the left of the actual file content being shown, I would like a gutter or a right side annotation column showing some kind of annotation of where this change came from. Since Mercurial hex ids are relatively unfriendly and unhelpful, and since repository-local-revision-numbers are repository local, I think that a short text description based on commit comments would be most helpful. Of course, with Mercurial, 99% of these commit comments are going to say "Merge", and nothing else. (Groan.) But lets pretend for a minute that we weren't using tools and workflows that left us that crippled at merge time, and instead, that we could have a useful commit comment show up each time:
Right now the workflow for complex merges looks like this for me:
Using my distributed version control tool (mercurial), pull changes from another repository which is in effect a branch. Merge. The merge window for TortoiseHg is usually where I start all this from. This in turn lets me configure a merge tool (beyond compare or Kdiff3).
However, it does not appear that there is any merge tool (that I have seen) that can be told, "hey you're not just merging two way or three way with different versions of a file in the two completely different folders, with the names I told you, but those files are also files that have a complete edit history available to you to show your human the actual context, the commits that those line changes came from with their commit comments, often having a bug number as part of the commit which will give the person doing the merge the ability to see What in the Heck is Really Going on.
I would change from Mercurial to Git, for example, even, for a real merge experience that didn't force me to do manually what I think my tools could be doing for me automatically. I'm using Mercurial, TortoiseHG, and KDIFF3, and if I could just change from KDIFF3 to some other tool, or do ANYTHING at all to get annotations and merges together on one screen, I would like to do so.

EGit Conflict Resolution GUI?

I think I am just merely (coming from an SVN background) confused with how Git conflicts are handled by EGit within Eclipse.
I understand that it shows textually in the normal standard method by which to show conflicts as stated here: http://www.kernel.org/pub/software/scm/git/docs/git-merge.html#_how_conflicts_are_presented however it isn't very clean and with thousands of lines of code it becomes unmanageable to avoid accidently deleting lines that are not meant to be deleted.
Is there any GUI within EGit that can show me each conflict with an step over ability?
I have searched around and I heard about the merge tool however when I follow the instructions by right clicking on the top level node of the tree (i.e. right click models folder that has the <> type icon denoting a conflict, which has a conflicted file of User.php within it) the merge tool is greyed out.
Am I using the merge tool wrong?
Edit
I found out that a bug can cause EGit merge tool to not show: Why is the merge tool disabled in Eclipse for a EGit-managed project? however I am using EGit 1.3.0 so I should be way past this bug.
I have given this question two days both here and on the EGit forums: http://www.eclipse.org/forums/index.php/t/371459/ unfortunately (even after everyone viewed it) no one had a real answer so I decided to solve my conflicts manually and just merge that way.
This way was, in reality, quicker and easier than trying to solve why the merge tools were not working for me, ironically.

How to merge code changes using subclipse?

I'm using svn for the first time, to maintain a custom version of Wordpress. I'm using the subclipse plugin in eclipse. The time has come to merge the changes in the latest release of Wordpress with my customised code base.
I have tried creating a branch and adding the new Wordpress release there, then performing a merge. No changes were made however.
Could someone walk me through the setup of project like this? I fear I am missing something basic.
Thanks.
This is assuming you merge from branch (containing the latest version of Wordpress) to trunk (your customized codebase).
(Make sure that you have committed everything you need into branch.)
Team --> Switch to another branch/tag/revision... your working copy to trunk (the target of your merge operation), and resolve any conflicts that come up at this point.
Team --> Merge opens a dialog where you will be performing the merge operation. Change the "From" URL to reference branch (the source of your merge operation, i.e. what you want to merge into your working copy). "From Revision" should point to the revision in branch where you want your merge operation to "start" from - typically the revision that was last merged in from branch to trunk (or most likely the head revision in your case, if you really want to merge just that latest changes in branch).
Set "To Revision" to point to the latest revision in branch (= the head revision).
At this point you are ready to perform the merge - Dry run command lets you preview what will happen during the merge, and Merge will perform the actual merge.
Once the merge operation has been completed, you need to make sure that all changes that were performed against your working copy are ok, and resolve all conflicts.
When you're done with resolving conflicts and reviewing the changes, commit the changes to trunk in a single commit operation. For your own convenience, it is strongly recommended that you add a commit message where you specifically state what this commit is for ( = merging revisions from X to Y from branch to trunk, what was the purpose, etc.).
Hope this helps.
Converting wordpress project to vendor branch procedure
If you are using svn for the first time I suppose you have not started with a clean wordpress copy, branched from there and edited the branched version, have you? ;)
If that is so you might have a problem at your hands.
Background
Unlike "regular diffs" SVN merge does not compare right-side code/folders with left-side code/folders.
While svn merge might fall back to a diff-like mechanism if it does not find a history, I would not recommend relying on that as it can be quite prone to unneccessary conflicts.
SVN Merge is used to reproduce changes that have been recorded in the SVN history. It is like telling a painter "Hey you know how this picture looked before you added that tree on the hill? That Tree was great! Look here i've copied the same base picture but now it's with a sunset. Can you paint the same tree again but on this picture with the sunset?"
The painter might be able to reproduce the tree because he knows how he had done it. He might even have a draft somewhere.
The picture, that is wordpress. The painter, its svn with you commanding it. The tree thats your modifications. The picture now sunset-themed is the newer wordpress version.
What most likely you did is copy wordpress vanilla into your svn, modify it, work with it.
To stick with the picture example, the history would contain commands like "copy whole picture, add tree, add leaves".
Now you bring a new version of wordpress, a new picture so to say and put it besides your older modified version. The Problem is, you human and smart know its quite much the same picture and even though the newer verison is different you just have to copy the tree, SVN does not have that knowledge. For SVN your wordpress 1.7 folder (modified) is completly distinct from wordpress 1.8. They share no history because nothing in SVNs log indicate it. SVN is a bureaucratic snob isn't it? ;)
Now what people do to allow svn to maintain that historic connection between wordpress 1.7, your modified 1.7 and the new 1.8 is they use branching right at the beginning of their works.
So you would start off with a clean 1.7 wordpress in a "vanilla-wordpress" folder, store it in svn and branch it to, say, "my-modified-wp". There you hack away until you feel like updating wordpress from upstream. People then download the latest wordpress copy overwrite their vanilla wordpress and merge the resulting changeset.
In the picture example commands would be these:
"Buy original picture
copy original picture as my picture
draw tree on my picture
draw sunset on original picture (someone else did that for you, aka update)
*reproduce* sunset on my picture too"
You can cleanly reproduce the sunset because you know how the picture looked before the sunset was applied.
Your problem though is that you did not start that way off but edited on your downloaded wordpress right away. So your newer copy of wordpress can not be easily associated with your modified version.
One way to establish history relations
download the **exact** wordpress version you started your project with
Put it into /vendor/wordpress/current
invoke "svn copy http://svnserver.tld/repositorypath/vendor/wordpress/current http://svnserver.tld/repositorypath/vendor/wordpress/1.7.1" to tag the import.
invoke "svn copy http://svnserver.tld/repositorypath/vendor/wordpress/current http://svnserver.tld/repositorypath/branches/my-new-modified-wordpress" or whatever your project/WP-edition is called.
Now comes the trick part
Scroll back the svn log of your "old-modified-wordpress". The one that you did not branch. You have to find the first revision AFTER your initial import of the old wordpress. Once you found that revision you take its number and use it in the second of these two commands:
change into a local checkout of "/branches/my-new-modified-wordpress"
issue "svn merge -r **4**:HEAD http://svnserver.tld/repositorypath/my-**old**-modified-wordpress". If 4 was the first revision during which you made own modifications.
You are telling svn the following: "Take all changes in my old branch between revision 4 and NOW and reproduce them on my new branch."
If all works out you should have two identical branches. the old-modified and the new-modified with the slight difference that the new-modified has a solid history with your "/vendor/wordpress/current" branch.
This ancestry allows you to contunously do the following:
Download the wordpress version you wish to upgrade too and **overwrite** /vendor/wordpress/current
invoke "svn copy http://svnserver.tld/repositorypath/vendor/wordpress/current http://svnserver.tld/repositorypath/vendor/wordpress/1.9.3" to tag the new version.
change into local checkout /branches/my-new-modified-wordpress
issue "svn merge http://svnserver.tld/repositorypath/vendor/wordpress/current"
profit
This procedure I describe with less storystelling at the link allready. But before it can work you have to establish the ancestry relation between the branches.
Subversion svn:externals file override?
I know it has been alot to read :). If you plan do soem drawing, think of "change commands" not states and you'll be fine.
C