2

I am trying to select/edit changes from another branch before merging - e.g., after a fetch.

When there are conflicts, it is easy to go to a conflicted file and remove/edit the text between '>>>' and '<<<'. But when there is no conflict it seems that the usual way is to edit hunks like I have found in some answers answer1, answer2:

git checkout -p 

or

git add -p 

However, despite the simplicity of the hunk editing, a single (after splitting) long hunk sometimes is not practical to be correctly edited. I suppose the difficulty comes when the number of lines changes or ' ' lines are unwittingly removed or transformed into '+' lines. Another problem, maybe even more important, is that the whole file is not available. There are text gaps between hunks that otherwise could make editing more comfortable.

One solution I think of is to simulate all changes as conflicts. Is that possible? This answer suggests a complex sequence of commands with a comment suggesting a equally complex (to be used at git root) alias:

git config --global alias.remerge '!sh -c "git show HEAD:${2} > ${2}.HEAD; git show ${1}:${2} > ${2}.${1}; git show $(git merge-base HEAD ${1}):${2} > ${2}; $(git config --get merge.tool) ${2}.HEAD ${2} ${2}.${1};"' 

Another answer for the same question presents the least confusing solution that is to check out the other branch in a different working copy, which weirdly remembers me of my SVN remote past.

None of the solutions seems adequate to be performed on a routinely basis.

[An example of scenario is when I receive code or text files from someone that is supposed to perform approximate contributions, that need corrections regularly. A more concrete case could be a software spec or even code or a scientific paper being fetched from a software architect or a supervisor after his/her fast-and-dirty review.]

2
  • Is there a reason you can't just add another commit to that branch with the changes you want, then merge? Commented Jul 5, 2015 at 18:16
  • Because I want to be able to edit the changes to be made to the file, not the changed file. E.g., If the other person deletes lines, they simply do not appear on the file; so I could not know that without resorting to a diff (git diff). The problem is resorting to a diff for every change. The hunk editor is half way to solve this, but I hope there is a more practical solution. Commented Jul 5, 2015 at 22:46

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.