Home > Back-end >  No CVS style merge changes in git? Using VSCode and Gitlens. I just want to keep or ignore changes i
No CVS style merge changes in git? Using VSCode and Gitlens. I just want to keep or ignore changes i

Time:12-17

This feels like a question I should be able to find already answered but I can't seem to find one and I imagine many posts I've read actually intended to ask what I'm about to try and explain. I'm using VSCode, I have Gitlense if that matters.

I'm a former CVS user. I like git much better... except merging changes. I might have been spoiled by the CVS gui or something:

When I had made local changes that differed from what was in my CVS repo I was able to view the diff just like git: the repo copy on the left and my working copy on the right. Totally makes sense. The lines in the diff were marked differently (the questions I've been able to find) but what I really miss is the ability to CLICK on a change and MOVE it over to the working copy or ignore it. After I had merged these changes I could then check in my changed file.

In git, what I'm finding is... First of all, I can't pull if I have local changes. I have to stash them, the pull, then pop, then diff. I can view the diff as I'm familiar with. Then if I see a change, I'm not allowed to modify my working copy in the diff tool. I have to copy from the diff, goto my working copy, paste the change, go back to the diff and continue scrolling line for line.

Is there a tool or a step I'm missing? I simply want to click a button and move the changes over to the working copy. I'm ok with stash then pop but it seems a little silly to do it every time.

Just now I had to stash over 20 files, pull a whole bunch, and I'm about to do the stash pop and resign myself to spending the day merging changes. Is there an easier way?

CodePudding user response:

Firstly, neither CVS nor Git has a single standard GUI, so the reference to "clicking" suggests that part of the difference is not between CVS and Git but between the GUI tools which you have used. There are many GUIs for Git, and integrations with IDEs, of varying quality and complexity. So, for that part, the real question is probably "how do I find a better Git GUI?" (The answer is to search around for one you like the look of and try it out.)

Secondly, git places a much bigger emphasis on commits and branches, rather than files and changes. Branches in git are cheap, and it's common to create new branches every single day.

So the process you're describing with local and remote changes is generally managed in git with multiple branches, and merging between them:

  1. You create a branch "feature-123", and commit your changes as you go
  2. Your colleague creates a different branch "feature-456".
  3. Your colleague finishes first, and merges "feature-456" into a shared branch (e.g. "main", "master", or "develop").
  4. To fetch their changes, you first commit what you have so far, then use "git pull" to merge the shared branch ("main"/"master"/"develop") into your working branch ("feature-123").
  5. At this point, you are presented with the conflicts between the two branches, resolve them, and commit the result.

You might occasionally use "stash" instead of "commit" at step 4, but it would be the exception rather than the rule.

You might also prefer to use "rebase" instead of "merge", but the result is similar.

The crucial part is that two people rarely commit directly to the same branch. Each developer commits to their own branch, and shares it in some way - often using a "Pull Request" or "Merge Request" on some central server like Github, GitLab, BitBucket, etc.

CodePudding user response:

I marked the question answered, as @IMSoP (how do I @mention here?) gave a very complete answer (thank you). For anyone who stumbles on this, in addition to the accepted answer, this is what I did in order to get the GUI I'm used to.

I used an external diff program. Not ideal but I installed Meld (https://meldmerge.org/), then the Meld Diff extension. I had to go to extension settings and put the full path to Meld.exe (for me it was "C:\Program Files (x86)\Meld\Meld.exe"), and then I was able to right click on a file with conflicts and select "Open with meld diff" and the meld gui comes up to compare and merge as I'm used to.

Now I need to study the full answer to this question. I've not been using branches... I suffer from CVS branch PTSD.

  • Related