2

enter image description here

This is what I want to achieve.
How can I remove first commit of feature on remote repository? Thank you in advance.

Yumi
  • 23
  • 1
  • 6
  • Why? What is the actual problem you're trying to solve? Generally, trying to change history in any sort of change tracking system is a bit against the point of that system. – David Sep 07 '21 at 18:47
  • @David First there feaure branch create from develop and have just 2 commits. I try to create experimental branch from develop and I commit just adding text file then I want to rebase feature branch from develop to this experimental branch but something go wrong I do some mistake and feature branch is be merged into experimental branch. After that I try to delete experimental branch so now the result is like in the pic. So the commit1 is the commit of experimental branch that is deleted. – Yumi Sep 07 '21 at 18:52
  • 2
    Note: the commit you marked with a red X is *not* the *first* commit on `feature`. It is the third-from-last commit on `feature`. The *first* commit on `feature` is the first commit that is on `develop`. This matters for multiple reasons; the most important is that you can't really delete *any* commit, and what you'll do instead is *copy* the *last two* commits on `feature` to new and improved commits that don't use the third-from-last commit. You have to "work backwards" like this, because Git works backwards. – torek Sep 07 '21 at 18:55
  • When you do this sort of "copy to new and improved" trick, the last step is to move the *branch name* so that it refers to the last copied commit. This doesn't move any *other* branch name, so all the commits that were on the other names, are still on the other names, perhaps including the copied-to-new-and-improved commits. – torek Sep 07 '21 at 18:57
  • Fortunately for your particular case, the commit you don't want to see any more is *only reachable from `feature`*, so the fact that it remains reachable from all the non-feature names that reached it before ... becomes irrelevant: there are no such names. But when that isn't the case (which you'll hit someday), it will matter. – torek Sep 07 '21 at 18:58

1 Answers1

3

Assuming you are the only one working on this branch, you can rewrite the history with an interactive rebase.

I recommend you document yourself a bit about interactive rebase first.

git checkout feature
git rebase -i HEAD~3 # Rebase the last 3 commits

In the editor opening, set drop operation for commit1. Save.

And then push (force) the changes with git push --force-with-lease.

Gaël J
  • 11,274
  • 4
  • 17
  • 32