3 ms·
As a developer who often needs to revert other developers' screwups (and sometimes my own): "git show COMMIT_ID -- somefile | git apply -R"
by kahlonel 8y ago
As a developer who often needs to revert other developers' screwups (and sometimes my own): "git show COMMIT_ID -- somefile | git apply -R"
- Lord_Zero 8y agoGit noob here, what does this do? I have read the docs on apply but I don't really understand patches. It sounds like you bundle a bunch of commits and allow someone to use them. But in that case, wuldnt you just push a branch and then the person who needs it can pull and merge it or rebase onto it or cherry pick it?
- NateEag 8y agoIt undoes the change made to `somefile` in `COMMIT_ID`. Details: `git show <COMMIT_ID>` gives you the patch identified by COMMIT_ID. Appending ` -- somefile` narrows that patch down to only include the specified path. The `-R` option to `git apply` tells it to apply the patch in reverse. Thus, "undo the changes in `somefile` from this commit".
- maccam94 8y agoIsn't that the same as `git revert $commit` ?
- schrodinger 8y agoI’m guessing that it’s different in that it only reverts one file, not the entire commit.