Git Tips Slides
PageUp x2: previous · PageDown x2: next · Home: index

Pick some lines from another branch with git difftool

Imagine you want to take some changes of a different branch into your code.

If you care about the lines of code, not the commits, then you can use the following way to get the changed lines into your code.

Switch to the branch that should be updated.

git difftool other-branch -- your-file.txt

This will open meld and you can take some lines to your local version.

This is related to Restore interactively, but the use case is different:

  • git restore -p -s other-branch your-file.txt: interactively restore selected hunks from other-branch
  • git difftool other-branch -- your-file.txt: inspect another branch side by side and copy over only the lines you want