0
  1. I had made 4 commits
  2. and a pull request for the last one.
  3. Merged that pull request.
  4. New information appeared and I have to return back to the second commit.
  5. I had "reset current branch" in Git-extensions to the second commit.
  6. I had created a new branch
  7. I had force pushed the branch
  8. I had tried to create a new pull request. enter image description here

enter image description here

-> I cannot, getting: Branch "target" is already up-to-date with branch "the-name-of-the-new-branch" in repository "repo".

If I am doing it remaining in the old branch, reaction is the same, only the name of the branch is different.

I have looked on SO for the problem, but there are not that info on bitbucket.

Instead of rollback, I have tried to revert the commits 3 and 4 - The result is absolutely the same. On the other hand, it is natural - the code in commit is the same, too.

I had added a line in dividing one operation in two, in order for code to look differently.

Bitbucket again refuses to create a pull request:

There is already a pull request open between bugfix/IDM-2782_rollback and develop. View the pull request. 

I go to that old pull request and decline it

Again trying to make the new pull request:

This pull request can't be merged.
You will need to resolve conflicts to be able to merge. More information.

"More information" tells me to make the merge with 'develop' branch. But I had made it already. Just now. Just before the order to make the pull request.

Gangnus
  • 24,044
  • 16
  • 90
  • 149

2 Answers2

1

Pull requests and merges only allow you to add commits. They do not allow you to remove them. To remove commits from a branch, you cannot use a pull request nor a merge. Instead, you must reset the branch to the last commit which you want to keep:

git checkout develop
git reset --hard <sha1 of the last commit you want to keep>
git push -f origin develop

This is only suggested if you are the only person working on this project. If you are working with a team and others have pulled develop, then you should not reset it. Instead should revert the commits you want to "remove".

git checkout develop
git revert <sha1 of a commit you want to "remove">

Note that this does not actually remove any commits. Instead it creates a new commit which reverses the changes of the commit you select.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • Sorry, what forked repo? How should I make one? Could you add a point about that, please? – Gangnus Feb 26 '18 at 14:45
  • @Gangnus I answered based on some assumptions. Please see my edited answer for a better solution to your problem. – Code-Apprentice Feb 26 '18 at 14:50
  • I don't want to reset "develop". I want to rollback changes made on several files by two commits. – Gangnus Feb 26 '18 at 15:43
  • AFAIK, I can find difference between my 4th and 2nd commits and apply that difference to the current state. I only don't know how to do it... – Gangnus Feb 26 '18 at 20:49
  • I thank you for your participation, and upvote, but as I have the project with many changes of many people, I cannot use this way, exactly as you say. – Gangnus Feb 26 '18 at 21:07
  • At last I did it by several "revert". The most disgustful was that it was not enough and I had to repair the code by hand in many places anyway. Of course, many merges, too. But I cannot explain how I did it to anybody. It was a total mess. – Gangnus Feb 27 '18 at 09:06
  • The main problem - I do not understand why BitBucket refused to create a pull request till some point and then, suddenly - allowed it. After that it was merely a question of correcting some lines in some files. – Gangnus Feb 27 '18 at 09:08
  • 1
    @Gangus The short answer is that a Pull Request always creates a merge and a merge can only add commits. – Code-Apprentice Feb 27 '18 at 14:33
  • Are you sure? I would say that when we create the PR BitBucket *tries* the possible merge for conflicts. But that does not matter, for my PR refused to be created not because of conflicts, but because BitBucket saw some commits in other, already created PRs. Even if the last commit was absolutely new. It seems I simply ran into some BitBucket bug. – Gangnus Mar 02 '18 at 11:55
  • @Gangnus The message in the screenshot in your question means that the `develop` branch already contains all of the commits from the `bugfix` branch. – Code-Apprentice Mar 02 '18 at 15:43
  • But it was not so! I just specially changed a pair of lines to have a definitely different commit. Declined old pull request. Pushed to the branch. And tried to create a new PR - with the result that you see. – Gangnus Mar 04 '18 at 10:56
1

Also reset the branch you merged into, to before the merge. Once you've merged history into a branch it's permanently part of that branch's history unless you reset it somehow.

It's the history that's important, the commits, not what any currently-particular commit happens to be called at the moment in this or that repository.

jthill
  • 55,082
  • 5
  • 77
  • 137