Git merge conflict resolution: reverse order of (current & incoming change) - visual-studio-code

Doing a git merge master on a branch, and conflicts are usually displayed in a file as follows:
<<<<<<< HEAD
=======
>>>>>>> master
In Visual studio, you get an option to Accept Current Change | Accept Incoming Change | Accept Both Changes.
Now I want to accept both changes, however, they are in the wrong order. If only the master's change was first, then they would be in the right order and I wouldn't need to move things around.
Have many such conflicts and looking to see if I can somehow display the master's change above HEAD's, and thus enable a quick Accept Both Changes resolution.
Any way to do this?

Related

What does the "+" sign next to a branch name indicate in VS Code?

In VS Code there is a "+" sign next to my branch name. What does that mean?
Checking the source code reveals that:
* indicates you have unstaged changes (not been added yet)
+ indicates you have staged changes (added, but not commited)
! indicates unmerged conflicts
There can also be Rebasing at the end, when you are in the middle of a rebase.
So, if you see *+, then git status should show some staged and some unstaged files.

Handling [re]moved lines with Meld visual diff and merge tool

I have a question about the Meld visual diff and merge tool, which is probably a simple misunderstanding.
But how do I adopt lines that were removed in the $REMOTE?
Please see the screenshot below for an example. I have changed the order of the imports and created a merge conflict, so now I want to pull the first change from the right, but then also the second change that would remove those lines that now already exist at top of the imports. I could remove them manually of course, but surely there is an easier way?
Or am I wrong with my assumption, that the middle pane is the result that gets written to $MERGED?
Edit: In this contrived example, I actually have a Delete action that I can use to remove those lines. But in a real-world merge I'm trying to do with meld the Delete action is greyed out, as is the Pull from Right action.
Any idea why Meld wouldn't allow me to Delete those lines that will be made obsolete by a Pull from Right above them?
I found out that holding the Shift key allows me to remove individual changes.

How to cleanly clipboard copy code from a GitHub.com diff?

Consider the following split view code diff from a browser on GitHub.com:
While looking at this diff, I want to clipboard copy the code from the right-hand side (e.g. in order to paste that snippet into a different project in another window).
However, if I try to use the mouse to select the code on the right-hand side in the usual fashion, the code from both sides ends up selected:
And if I hit Ctrl+C / Cmd+C, I end up with kind of a mess on my clipboard which includes copies of the code from both sides, and all of the + and - indicators, which leaves me with a lot of error-prone manual cleanup to do after I paste. (Particularly when copying from a diff that's more long and complex then the simple one I picked out for illustration purposes in this question!)
My question: How can I cleanly and easily copy code from one side of a split view diff in a web browser on GitHub.com to my clipboard?
Update March 2021: this should be, this time, supported:
Copy one side of split diff
When comparing changes to a file using the split view, you can now select and copy just one side of the diff.
Previously both sides were copied. Selecting over a comment will still copy the comment's contents.
May 2018:
As mentioned by Hugo Giraudel in his tweet in late April 2018, a bit too quickly:
GitHub finally moved the + and - symbols from diffs to CSS pseudo-elements, making it possible to copy code directly from a diff without having to clean it up.
That is long overdue and fantastic. ✨
Actually... this is only true with the help of third-party extension!
Like sindresorhus/refined-github.
Without, you would still copy the '+' and '-'.
GitLab has that feature though.
This is still pending for BitBucket (issue 16204)
timotheecour reports in the comments that it does not help with side-by-side diffs:
the code from both sides ends up selected
This is in the context of using refined-github, a Browser extension that simplifies the GitHub interface: issue 2765.
Update Nov. 2020: that issue just got resolved with PR 3698

In Mercurial, how to "merge" with the commit's (single) parent?

I've worked on some project. I'm able to see the difference between my project and its (sole) parent with:
hg kdiff3
(After I've configured "kdiff3" as shown here). However, I want to be able to edit my files, perhaps remove some of my changes, edit some of them or make new changes. But that command only shows me the differences, rather than let me edit them. If I try:
hg merge 5861231e8335
(When "5861231e8335" is the (sole) parent of the working directory) I get:
abort: merging with a working directory ancestor has no effect
So how can I "merge" with the parent? (preferably using "kdiff3")
First, you have misunderstood what hg merge does. It merges changesets from 2 parents. It doesn't merge uncommitted changes.
To merge uncommitted changes into the current tip changeset, you want:
hg commit --amend
which replaces the current tip with a new one.
To answer your question about editing in a differencer. I'm not aware of any method of editing a bunch of files in a file differencer; that's because the set of files get copied into the temp directory where it's obviously pointless to edit them. You can however, diff and edit one file at a time because one file is diffed in place without copying to the temp directory.
But surely, isn't it better to edit files in your normal editor rather than in a file differencer? Surely, one can edit, but only as a last resort. OTOH, if you use the trick of viewing diffs one file at a time, it is possible to edit in your real editor, then watch the diffs change in the differencer.
hg shelve lets you temporarily put aside (on a shelf) parts of the diff between the working directory and its parent, so it will give you the "remove some changes" part of what you want. It does not let you edit, but you could put what you have changed on one shelf, then reimplement the change. If you want to revert to the original change, you just put the new change on a new shelf, and pull the original change off its shelf.
Alternatively, create a copy of the parent changeset using hg export (or hg clone and update to the parent changeset, but you don't need the history for this), Once you've got your copy, you can merge the copy of parent with your working directory using kdiff3 directly, outside of Mercurial.

Discard remote changes in SmartGit/Hg

How can I discard remote changes in binary files when merging? There is only menu item to discard changes in local file. When I'm trying to "resolve" it tells it can't do that thing for binary file.
Sorry, I've mentioned "resolver" menu but it was "conflict solver". Log http://pastebin.com/xhGuc3du.
Although when I'm using "resolve" I see OK icon in the operations log (right bottom corner) but "conflict" label does not disappear. Log http://pastebin.com/DEDWQSht.
To discard remote changes, Local|Discard should be sufficient. To set your local content either to your own version before the conflict ('ours') or to the remote version ('theirs') use Local|Resolve and select the corresponding option there.