Skip to content

Instantly share code, notes, and snippets.

@hardikmdev
Last active May 30, 2022 08:00
Show Gist options
  • Save hardikmdev/b878ca2c02ff44c9a4ca06ac2bdca998 to your computer and use it in GitHub Desktop.
Save hardikmdev/b878ca2c02ff44c9a4ca06ac2bdca998 to your computer and use it in GitHub Desktop.
GIT :: stuff

checkout content from a different branch.

git checkout targe_branch
git checkout src_branch  -- <content_dir>
git add <content>
## and continue... 
git diff -w --no-color | git apply --cached --ignore-whitespace && git checkout -- . && git reset && git add -p

git diff -w --no-color (creates a diff)
git apply --cached --ignore-whitespace (applies the diff ignoring whitepace, and indexes it)
git checkout — . (removes the unindexed “whitespace” changes)
git reset (resets the index to just he non-whitespace cahnges)
git add -p (adds the non-whitespace changes in patch mode)

# Or create a command to it
alias gwap=“git diff -w --no-color | git apply --cached --ignore-whitespace && git checkout -- . && git reset && git add -p”
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment