How do I delete commits from git and consider the old with new implementations?

Asked

Viewed 101 times

0

Personal I have the following problem, I was developing and comiting slowly the changes, when I arrived at a certain point I had to go back in one of the commits using:

 git reset --hard <numero do commit> 

Because I saw that after it a functionality stopped working.

Only I ended up leaving in this commit that I came back and implemented more things. When I went to do the push, obviously gave r. Asked me to do the pull, I just don’t want to give pull of commits after that, I just want to upload the commit that I came back with the new implementations that I did on top of it.

Does anyone know how to outline this without losing the data I implemented in the old commit? I want to be able to discard the commits in front of it, and just consider this commit with the new things I committed last.

  • can use the push command with the --force flag. This flag overrides the contents even if the remote is in front. Before you run, read the documentation, see if this is really it: https://git-scm.com/docs/git-push

  • 1

    @Pedro do not recommend. It would be better to make a branch from the desired point and "pick cherry" the desired changes

  • 1

    @Jeffersonquesado, I agree, the push-force is a bit dangerous, and the Cherry pick on a separate branch would be the best way. However, I recommended this method for the phrase "I want to be able to discard the commits in front of it..." , which cannot be done with Cherry / merge

  • @Jeffersonquesado but after I got back to branch x, I committed other things on top. I’ll lose them too?

  • @Gabrielamendonça you have the gitk installed in the machine? If yes, you can show your commits tree, could you climb the commits tree in question? I didn’t understand what you said in the comment, I was lost

  • @Jeffersonquesado I put in the answer there the image

  • 2

    @Gabrielamendonça girl , you should give a [Dit] in the question , not for an answer. What you put is not an answer, it should just be an issue of the question

  • 1

    @Jeffersonquesado young beauty, gives next issue. thanks! I’ve solved here with the same force. Thanks!!

  • Your problem remembers this one: https://answall.com/q/271209/64969; if it is, you can mark it as duplicate?

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.