How does one add patches from file X on branch1 to file X' on branch2 using Git - cherry-pick?

StackOverflow https://stackoverflow.com/questions/13236634

  •  27-11-2021
  •  | 
  •  

Pergunta

Esteemed Git users,

These post's appear to answer my question, but either i'm too new to Git to grasp & execute them correctly, or they don't in fact answer my question:

As the title indicates, i have a file, X, on branch1 and file X' on branch2. File X' was branched a few commits ago (to both file's X & X') from file X and i also changed the file name (i.e., from X to X'). The file's remain largely the same. What i'm trying to achieve is bring some of the changes made to file X over to X'. The changes are limited to two commits, commit_a and commit_b. Ideally (& optionally) i'd like to invoke my merge tool to manually accept (or not) specific lines of code within each commit_a and commit_b when applying them to X'. Is this possible and if so how? FWIW, I'm only using Git locally; no interaction with other collaborators/repositories. Trying to apply answers from the aforementioned posts, i could not focus only on the files of interest (branch1 X & branch2 X') - Git kept involving other files in the two branches, including files Y and Z (of both branches) as well as X in branch2, but never X' in branch2. I also want to keep branches1 & 2 separate so i don't see how the merge command would work here.

Being new to Git (and version control) i also question if my workflow is some how responsible for failing to achieve my objective here.

Patient exampled answers greatly appreciated!

Karl

Foi útil?

Solução

I would cherry-pick the commit that introduces the parts you want, then git reset HEAD^ to remove the most recent commit and leave the changes in the working copy, then git add -p the parts you want and make a new commit from that.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top