Permanent reset subcategory for a specific past state

In the git repository, I have a subdirectory that I want to reset for a certain state in the past (earlier commit). Is it possible to undo all file commits in a specific subdirectory? I think there are no commits that apply changes to files inside this subdirectory and to files located elsewhere at the same time. But would it be nice if you could leave commits on unaffected files that are not in this directory?

I do not need to delete the story. It would be nice to check the previous state, delete the current contents of the subdirectory and copy and fix the old state in its place. But in the end, there may be a more elegant (githonic) way.

+6
source share
2 answers

The easiest way to do this is to use the git checkout feature to apply in a subdirectory. Then complete the step and do:

 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>" 
+10
source

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

CharlesB's answer is a simpler approach if there are many commits, or commits relate to other parts of the project (but you could really get around this using the -n flag (not auto-comment) and only making changes that interest you)

+1
source

Source: https://habr.com/ru/post/915766/


All Articles