0

I need to do is to delete from the local and remote repo a group of commits, at the momment I have this...

* 927dbd9 practice  10 - Part 10: dewscription > I am here
* 4e1ea11 practice  9 - Part 9: description 9
* b6ce6b0 practice  8 - Part 8: description 8
* 2a82255 practice  7 - Part 7: description 7
* bdcc1c6 practice  6 - Part 6: description 6
* a17b194 practice  5 - Part 5: description 5
* fcfd229 practice  4 - Part 4: description 4
* d855dfe practice  3 - Part 3: description 3
* 4e1ea11 practice  2 - Part 2: description 2
* 4e1ea11 practice  1 - Part 1: description 1

I need to delete a specific group of commits, let's say practice 3 to practice 7. This deleted commits shouldn't affect the status of the lasts commits.

Is it posible to do that?

*Commits to delete* 
* 2a82255 practice  7 - Part 7: description 7
* bdcc1c6 practice  6 - Part 6: description 6
* a17b194 practice  5 - Part 5: description 5
* fcfd229 practice  4 - Part 4: description 4
* d855dfe practice  3 - Part 3: description 3

Thanks in advance!

SebDieBln
  • 3,303
  • 1
  • 7
  • 21
mabvmex
  • 61
  • 8
  • Why do you need to delete them? If they contain sensitive information, assume that information has already been compromised and needs to be changed anyway. If you still decide to delete them, use `git rebase -i` and inform anyone who might already have pulled the commits that they will need to update their repository after you have pushed the change. – chepner May 02 '22 at 15:07
  • @chepner Im trying to understand how git works about navigating branch/commits, there is not relevant info on them... but thanks for your recommendations – mabvmex May 02 '22 at 15:16
  • Reset locally on the commit you want to be the last, then push to remote with `--force`. – Romain Valeri May 02 '22 at 15:18

1 Answers1

1

You need to do

git rebase -i HEAD~10

Then keeps the ones you want and remove the lines containing the rest. Save and exit. Then to push:

git push --force-with-lease

Don't --force.