Permanently reset subdirectory to specific past state

后端 未结 2 349
你的背包
你的背包 2021-01-05 17:31

In a git repository I have a subdirectory that I want to reset to a specific state in the past (an earlier commit). Is it possible to undo all commits on files in a specific

相关标签:
2条回答
  • 2021-01-05 17:41

    The simplest way to do it to use the ability of git checkout to be applied on a subdirectory. Then stage and commit:

    git checkout <old-SHA1> -- path/to/subdir
    git add -A path/to/subdir
    git commit -m "reverted files in path/to/subdir to what it was at <old-SHA1>"
    
    0 讨论(0)
  • 2021-01-05 18:08

    If you work out all of the commits that you want to undo, you can use git revert to back them out - this would be most useful if there was only one or two commits that were the troublemakers.

    CharlesB's answer is a simpler approach to take if there are lots of commits, or the commits touch other parts of the project (but you could actually work around that by using the -n (don't autocommit) flag, and only committing the changes you are interested in)

    0 讨论(0)
提交回复
热议问题