Skip to content

Instantly share code, notes, and snippets.

@hoangitk
Last active March 11, 2022 06:18
Show Gist options
  • Save hoangitk/e242a180ffa1fa3c0235ab45336aaf18 to your computer and use it in GitHub Desktop.
Save hoangitk/e242a180ffa1fa3c0235ab45336aaf18 to your computer and use it in GitHub Desktop.
[Git Practice] #git

Git Practice

Ad-hoc merge specific file from branch

Credit: https://stackoverflow.com/questions/18115411/how-to-merge-specific-files-from-git-branches When content is in file.py from branch2 that is no longer applies to branch1, it requires picking some changes and leaving others. For full control do an interactive merge using the --patch switch:

$ git checkout --patch branch2 file.py

The interactive mode section in the man page for git-add(1) explains the keys that are to be used:

y - stage this hunk
n - do not stage this hunk
q - quit; do not stage this hunk nor any of the remaining ones
a - stage this hunk and all later hunks in the file
d - do not stage this hunk nor any of the later hunks in the file
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help

The split command is particularly useful.

Download specific folder

- Flow
```cmd
git clone --depth 1 --filter=blob:none --no-checkout https://github.com/your-git
git sparse-checkout set <folder>
git checkout <branch>
```
- Eg: you want to download only "sandbox" folder in https://github.com/openiddict/openiddict-core
```cmd
git clone --depth 1 --filter=blob:none --no-checkout https://github.com/openiddict/openiddict-core
git sparse-checkout set sandbox
git checkout dev
``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment