Ah, the dreaded resolve conflicts message. You've finished crafting the perfect code, just a quick merge in of master (ahem, main) before you submit your PR, and then... 💥
If only there was an early warning system for merge conflicts so you could be better prepared or even avoid the conflicts in the first place I hear you say? Well if you are a VS Code user today is your lucky day!
Firstly, you'll need to install and set up GitLive, then you should see this icon in the top right-hand corner.
It will be disabled if the file open in the editor is not from git or there are no other changes to it from contributors working on other branches (aka you are safe from conflicts). If it's enabled there will be one or more change indicators in the gutter of the editor.
These will show you where your teammates have made changes compared to your version of the file and even update in real-time as you and your teammates are editing.
If you've made a conflicting change you will see the bright red conflict indicator. These conflicts can be uncommitted local changes you have not pushed yet or existing changes on your branch that conflict with your teammates’ changes.
Hover your mouse over the code in the affected lines to see the diff between your version and theirs, the branch the offending changes are from, and the issue connected to that branch if there is one.
From this popup you can also cherry-pick your teammate’s change directly from their local version of the file. For simple conflicts this can be a quick way to resolve them as identical changes on different branches will merge cleanly.
Unfortunately, it's not always possible to resolve a conflict straight away but with the early warning, you'll be better prepared, avoiding any nasty surprises at merge time!
Check out this blog post or the GitLive docs if you want to learn more.
Top comments (8)
I don't know... this all sounds a bit overly eager and can become counter-productive. Some of the conflicts might not even end up in either my or my teammate's final commits/merge, or after I resolve the conflicts based on some early warnings, somebody else might push some further changes that conflict with my resolution again or render it moot.
I organize my changes into small, logical, and self-contained commits, and I constantly rebase my feature branch, on top of the base branch, so merges I have to do are typically very easy to resolve. So merge conflicts are almost never nasty for me.
Sounds like you have a very organized workflow! You might still find this feature useful though as the indicators can provide value beyond merge conflict detection, for example in an open source project they are a great way to discover what others are working on and if there are any possible synergies with the changes you are making. And for the times they prove to be more of a distraction you can always hide them.
You are right, I dont think this extension is useful,
It makes we distracted a lot, when we have to care about the conflicts not just one time but all the time,
I think you need to think bigger. On a project with hundreds of devs and many teams working against the same codebase for multiple releases up to a couple years ahead of time, this kind of 'situational awareness' can be invaluable.
I'm trying to understand, does this find conflicts with origin/main, all remote branches, your teammate's local commits, or your teammate's working tree? The latter two sound most useful but then it can't run completely local?
It finds conflicts with everything you mentioned, for the latter two it also requires them to have the extension installed
So useful to know as early as possible that you might have merge issues with your current task; being able to see what your colleague has changed means you have the chance of mitigating any merge pain!
Thank you for the post, I'll keep these tips in mind when merging PRs :)