-1

I have recently made commits that I want to delete, and return the folder to the state it was before the commits.

Here is an image of commit history in a folder:

How can I delete the commits made after e1c0013?

Orlyyn
  • 2,296
  • 2
  • 20
  • 32
  • Does this answer your question? [How to revert multiple git commits?](https://stackoverflow.com/questions/1463340/how-to-revert-multiple-git-commits) – Amit Dash Jun 25 '21 at 05:51

1 Answers1

2

Your screen capture indicates that 5 commits have been made on top of the e1c0013 commit. Assuming that you have not yet pushed this branch to your Git repo, you may use a hard reset:

# from desired branch
git reset --hard HEAD~5

If you have already pushed this branch to the remote, then you should instead revert the five commits:

# from branch "your_branch"
git revert your_branch~5..your_branch
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • I don't know what you mean by pushing branch to git repo? I have a master branch and I have already used pushed the commits. –  Jun 25 '21 at 01:02
  • 1
    If you have already pushed your branch with the commits which you want to delete, then you should use my second suggestion of `git revert`. – Tim Biegeleisen Jun 25 '21 at 01:03
  • So if my branch name is master then I should do git revert master~5..master? –  Jun 25 '21 at 01:08
  • But the commits are in a folder, how can I do that to a specific folder? –  Jun 25 '21 at 01:14
  • The commits are _not_ in a folder. A Git commit is a snapshot of your entire project, including all folders in that project. – Tim Biegeleisen Jun 25 '21 at 01:16
  • I got this error message: error: The following untracked working tree files would be overwritten by merge. What should I do? –  Jun 25 '21 at 01:24
  • Is your working directory dirty? If so, then you should first commit or stash your work. – Tim Biegeleisen Jun 25 '21 at 01:27