Home > Mobile >  git cherry-pick commit across linted code
git cherry-pick commit across linted code

Time:07-15

We recently linted out entire codebase. Yay! But now we're struggling to forward port patches across the linted commit. For example we have branches V1 and V2. V2 was created by linting V1 at some point in time. Now we want to cherry-pick a commit from V1 (orange) onto the head of V2. I'm struggling to get the commit to cherry-pick cleanly without a ton of conflicts. Any suggestions?

enter image description here

Edit: This is what I've tried

git checkout orange
Apply lint
git commit --amend --no-edit

At this point I have a orange' So far I've tried

git rebase HEAD~ --onto origin/V2
AND
git checkout origin/V2
git cherry-pick orange'


CodePudding user response:

What you're describing is normal and expected. Let's say we are on main and we have one file committed to our repo, 1.txt, and that it consists of

1
2
3
4
5

Now I'll make a change to that file and commit the change:

2
3
4
5
1

Call that commit unlinted changed. Now I'll go back to the first commit and start a branch; call it linted. Let's say that linting consists of adding semicolons to every line. So I lint and commit this:

1;
2;
3;
4;
5;

Now I'll edit that and commit the result.

2;
1;
3;
4;
5;

Now I will attempt to cherry-pick main:

% git cherry-pick main
Auto-merging 1.txt
CONFLICT (content): Merge conflict in 1.txt

And this is exactly what we expect. The two files have, in essence, nothing in common. We can see this clearly if we look at the markup in the conflicted file (I use diff3 style):

% cat 1.txt
<<<<<<< HEAD
2;
1;
3;
4;
5;
||||||| parent of d00743b (unlinted changed)
1
2
3
4
5
=======
2
3
4
5
1
>>>>>>> d00743b (unlinted changed)

By cherry-picking, you are asking the text in the middle to turn simultaneously into the first text and the last text. That's impossible. No machine can figure out what's happened here; it takes a human. That's what a merge "conflict" is: it's a request for human assistance. Assist, as requested.

CodePudding user response:

Got it to work

git checkout orange
Apply lint
git commit --amend --no-edit
git checkout origin/V2
git cherry-pick orange' -X theirs'
  • Related