I have three branches (let's call them master, testing, and feature). All three are shared, so I cannot rebase any of them without causing problems for others. Currently, all three branches have diverged (none is a fast-forward), so eventually some merging will need to done, since rebasing is not an option.
For the moment, though, I would like to pull in the Makefile from testing into feature, since feature was split off from master, and the Makefile was added in testing. I do not want to merge in any other changes between the two branches, however.
My understanding is that if I just git-add Makefile to feature, this will cause merge conflicts when I merge feature back into testing (and then master), especially if I make any further additions to the Makefile in my feature branch.
I could do git-cherry-pick; however, there were multiple commits to the Makefile in testing, and I assume there's a better way than trying to cherry-pick all of those commits into feature.
In Conclusion. We can use git checkout for far more than simply changing branches. If we supply it with a branch name and a file, we can replace a corrupted or broken file. Instead, if we want to pass some of the changed content we can use the --patch flag to manually merge an individual file.
While merging is definitely the easiest and most common way to integrate changes, it's not the only one: "Rebase" is an alternative means of integration.
If you use pull requests as part of your code review process, you need to avoid using git rebase after creating the pull request. As soon as you make the pull request, other developers will be looking at your commits, which means that it's a public branch.
You can just do a
git checkout branch_name <path(s)>
This can load a specific file but you can also use wildcards and directories
Note that:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With