Skip to content

Instantly share code, notes, and snippets.

@wulucxy
Created March 12, 2020 08:29
Show Gist options
  • Save wulucxy/fe9839ecf6f4bb9dc032ddd62f411380 to your computer and use it in GitHub Desktop.
Save wulucxy/fe9839ecf6f4bb9dc032ddd62f411380 to your computer and use it in GitHub Desktop.
git
usually use the -p flag with a git checkout from the other branch which I find easier and more granular than most other methods I have come across.
In principle:
git checkout <other_branch_name> <files/to/grab in/list/separated/by/spaces> -p
example:
git checkout mybranch config/important.yml app/models/important.rb -p
You then get a dialog asking you which changes you want in "blobs" this pretty much works out to every chunk of continuous code change which you can then signal y (Yes) n (No) etc for each chunk of code.
The -p or patch option works for a variety of commands in git including git stash save -p which allows you to choose what you want to stash from your current work
I sometimes use this technique when I have done a lot of work and would like to separate it out and commit in more topic based commits using git add -p and choosing what I want for each commit :)
------
从其他分支里面按照文件路径来选择指定的文件
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment