Created
July 18, 2023 21:21
-
-
Save zanieb/2bac264f0942f64a1083e5c226dbdcc6 to your computer and use it in GitHub Desktop.
Applies the contents of file(s) at the given ref (e.g. branch or commit) to the current working tree.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # | |
| # git-pickfile | |
| # | |
| # Applies the contents of file(s) at the given ref (e.g. branch or commit) to | |
| # the current working tree. If there are no conflicts, the changes will be | |
| # staged. If there are conflicts, the changes will need to be resolved and | |
| # committed. | |
| # | |
| # Unlike `git checkout <ref> -- <file>`, this allows you to resolve conflicts | |
| # instead of just discarding changes in the current tree. | |
| REF=$1; | |
| shift; | |
| FILES="$*"; | |
| if [ -z "$FILES" ]; then | |
| echo "Usage: git-pickfile <ref> <file> [<file> ...]" | |
| exit 1; | |
| fi | |
| set -euxo pipefail | |
| git diff $(git merge-base @ "$REF") "$REF" $FILES | git apply --3way |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment