3 ms·
Git commits always have a parent. Applying git patches to a repository without the parent is not going to work. The repository must have the parent commit. You
by jillesvangurp 3y ago
Git commits always have a parent. Applying git patches to a repository without the parent is not going to work. The repository must have the parent commit. You might force it to work without that but it's going to create conflicts, complicate merging, etc.
The reason is that a git patch is not merely a diff but an export of the actual commit objects and referred content (trees, blob diffs, hashes, etc.). Applying the patch recreates the exact commit objects on the other side. The end state is exactly the same as if you would have merged the commits from some branch. There is no difference.
Git diff, shows you a normal diff. It's not the same thing. You can indeed apply such diffs to your local work copy. But that's not the same thing as a git patch.
The commands you need are git format-patch (exports the patch) and git apply (applies it).
- cassianoleal 3y ago> Applying git patches to a repository without the parent is not going to work. If that's the case (and I'm not saying it isn't - I really don't know), how does cherry-pick work? I know I can cherry-pick commits in the same repo from entirely separate commit chains, where the only common ancestor is either my local HEAD or some other commit way below both of us. Why would that not work for different repositories?
- jillesvangurp 3y agoIt still uses the notion of a common parent to merge a single commit. Works as long as there are no conflicts. As to why that would or would not work, I refer to the git internals section of the Git book. Great stuff. But they are not performing any dark magic here.
- cassianoleal 3y agoSo are you saying that if I have completely disconnected commit trees in the same repo, git will refuse to cherry-pick between each other?