How to revert a specific file in a old commit on git

Marcos

I think my question is close to this one, but I'm using git.

So, let's say I have

Commit1 changed file1.c and file2.c

Commit2 changed file2.c, file3.c, file4.c

Commit3 changed file1.c , file2.c and file3.c

and so on...

Then, I would like to revert only the changes that Commit2 made in file2.c, but, try to keep the changes that Commit3 made in this file...

What you think? There is some way to do it?

Thank you.

user3159253

You may try to revert Commit2 (that is, apply a new git commit, whose changes would be opposite to the changes made in Commit2) but without committing. There's a instant menu entry in gitk for example. In this new commit you leave only changes made to file2 and commit the result.

Alternatively, you could simply do something like

git diff Commit2..Commit1 -- file2.c > revert.patch
git apply revert.patch

it might be useful to take a look on the patch before applying it because commits after Commit2 may introduce some conflicts with the changes to file2.c from Commit2.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Git: Revert old commit on single file

From Dev

Git : revert to old version for particular file with checkout command and commit

From Java

How to revert initial git commit?

From Dev

How to revert a unpushed git commit

From Dev

Revert changes to a specific file from a specific commit

From Dev

git revert on single lines in single file of commit

From Dev

git revert on single lines in single file of commit

From Dev

Git how to not include specific file(s) to commit

From Dev

How can I revert specific files of a commit?

From Dev

Git + Intellij - How to revert a local commit?

From Dev

How can I revert back to a Git commit?

From Dev

Git - How to revert entire directory to specific commit (removing any added files)

From Dev

How to revert changes to 1 file in previous commit

From Dev

How do i revert a commit and uncommit (?) a file?

From Dev

Intellij git revert a commit

From Dev

Revert files to a specific commit without affecting local repository git

From Dev

git: show the future of a file from an old commit

From Dev

GIT: Find a file in a specific commit

From Dev

Git fails to revert: Found a swap file "COMMIT_EDITMSG.swp"

From Java

How do you revert to a specific tag in Git?

From Dev

How to show Git merge commit details for a specific file

From Dev

How to add an empty git commit message to a specific file?

From Dev

How to revert old plsql?

From Dev

Can we say that a git revert merges the old previous commits on top of the reverted commit?

From Java

How do I "un-revert" a reverted Git commit?

From Java

How do I revert a Git repository to a previous commit?

From Dev

Git: How to revert a symlink commit which replaced a submodule?

From Dev

Git & CI: How to tag if build passes/revert commit if fails?

From Dev

How to revert my remote git repository back to a certain commit?

Related Related

  1. 1

    Git: Revert old commit on single file

  2. 2

    Git : revert to old version for particular file with checkout command and commit

  3. 3

    How to revert initial git commit?

  4. 4

    How to revert a unpushed git commit

  5. 5

    Revert changes to a specific file from a specific commit

  6. 6

    git revert on single lines in single file of commit

  7. 7

    git revert on single lines in single file of commit

  8. 8

    Git how to not include specific file(s) to commit

  9. 9

    How can I revert specific files of a commit?

  10. 10

    Git + Intellij - How to revert a local commit?

  11. 11

    How can I revert back to a Git commit?

  12. 12

    Git - How to revert entire directory to specific commit (removing any added files)

  13. 13

    How to revert changes to 1 file in previous commit

  14. 14

    How do i revert a commit and uncommit (?) a file?

  15. 15

    Intellij git revert a commit

  16. 16

    Revert files to a specific commit without affecting local repository git

  17. 17

    git: show the future of a file from an old commit

  18. 18

    GIT: Find a file in a specific commit

  19. 19

    Git fails to revert: Found a swap file "COMMIT_EDITMSG.swp"

  20. 20

    How do you revert to a specific tag in Git?

  21. 21

    How to show Git merge commit details for a specific file

  22. 22

    How to add an empty git commit message to a specific file?

  23. 23

    How to revert old plsql?

  24. 24

    Can we say that a git revert merges the old previous commits on top of the reverted commit?

  25. 25

    How do I "un-revert" a reverted Git commit?

  26. 26

    How do I revert a Git repository to a previous commit?

  27. 27

    Git: How to revert a symlink commit which replaced a submodule?

  28. 28

    Git & CI: How to tag if build passes/revert commit if fails?

  29. 29

    How to revert my remote git repository back to a certain commit?

HotTag

Archive