Difference between revisions of "How to do git tricks"
Line 13: | Line 13: | ||
Other than copy over the files I do not want changed manually, I do not know. | Other than copy over the files I do not want changed manually, I do not know. | ||
− | == | + | ==Patch== |
<pre> | <pre> | ||
git log -p -1 <sha1-of-your-commit> | git log -p -1 <sha1-of-your-commit> | ||
Line 20: | Line 20: | ||
"Git goes back in the history until the cherry pick source matches the target and creates the patch based on this revision. That's why more changes might appear ..." | "Git goes back in the history until the cherry pick source matches the target and creates the patch based on this revision. That's why more changes might appear ..." | ||
+ | |||
+ | <pre> | ||
+ | git log -p -1 <sha1> | git apply --3way - | ||
+ | </pre> | ||
+ | |||
+ | But this pulls more changes too. And without --3way fails. | ||
==Include branch from an unrelated repository== | ==Include branch from an unrelated repository== |
Revision as of 22:46, 19 January 2019
Comparing files
git diff branch1:full/path/to/foo.txt branch2:full/path/to/foo-another.txt
How to link to such comparison view on github?
Compare and copy files from other branches
https://stackoverflow.com/questions/2364147/how-to-get-just-one-file-from-another-branch
Cherry pick commit and update only some files
? Other than copy over the files I do not want changed manually, I do not know.
Patch
git log -p -1 <sha1-of-your-commit>
https://stackoverflow.com/questions/7802252/why-cherry-pick-pick-change-more-than-one-commit
"Git goes back in the history until the cherry pick source matches the target and creates the patch based on this revision. That's why more changes might appear ..."
git log -p -1 <sha1> | git apply --3way -
But this pulls more changes too. And without --3way fails.
git remote add rep2-git url_to_unrelated_repository git fetch rep2-git git checkout remotes/rep2-git/branch2 git checkout -b rep2/branch2 git push -u origin rep2/branch2:rep2/branch2
There is no need for the two repositories to have a common initial commit or anything. The commit hashes are preserved. You can even git cherry-pick commit from the other repostory and git will do pretty good job finding files to apply the commits to, even if the files have somewhat different names and are in somewhat different locations in the file two file trees.