-1

I uncommitted some commits that I pushed to a PR by doing a git reset --hard feature/DCMP-959.

Then I made some small changes and committed it with the correct message, but when I pushed it to the PR, it repushed the uncommitted commits I previously removed:

enter image description here

How do I completely eliminate commit 388be463463 and commit 6b3a92b79bb from my PR and leave the latest one?

I need to eliminate these commits because I am getting this error message:

JQL Check Unable to merge this PR because one or more referenced JIRA issues are not: a) Relevant to this project; b) An allowable issue type; c) In an allowable status; or d) Assigned a fix version and/or parent fix version

and my build failed.

Daniel
  • 14,004
  • 16
  • 96
  • 156
  • Are you looking to do a rebase: https://stackoverflow.com/questions/1338728/delete-commits-from-a-branch-in-git this question looks like it will point you in the right direction – Sweet Chilly Philly Jul 08 '19 at 21:25
  • What made you think the reset *"uncommitted some commits"*? Have you tried actually rewriting the history? Note you'll have to force push if you do so. – jonrsharpe Jul 08 '19 at 21:27
  • If your commits have sensitive information then it's worth fixing it. If it's only code bombs which you have fixed in the later commits I suggest leave it. It's just my personal opinion. To fix you have to reset to the commit before 388be463463 and then cherry pick or manually merge the commit you want – karthick Jul 08 '19 at 21:30
  • @SweetChillyPhilly, I tried that SO post, but found it became unmanageable for me. – Daniel Jul 08 '19 at 21:32
  • @karthick, I don't mind leaving it, but the merge failed with this error: `JQL Check Unable to merge this PR because one or more referenced JIRA issues are not: a) Relevant to this project; b) An allowable issue type; c) In an allowable status; or d) Assigned a fix version and/or parent fix version`. Is there a better way to resolve this error? Quite frankly, I never worked with Bitbucket before so I don't really understand it, but thought cleaning up all these commits that are essentially the same would help. The last commit is essentially a variation of the first two. – Daniel Jul 08 '19 at 21:33

1 Answers1

0

If you want to make 1 commit out of your changes in branch feature/DCMP-959 and merge it let's say into master, then:

git checkout feature/DCMP-959
git merge origin/master
# keep all the files as they are in working dir, but remove all commits
git reset --soft origin/master
git commit -m 'Nice looking message'
# will re-write the commits in your remote branch
git push -f origin HEAD:refs/heads/feature/DCMP-959

If you want to remove (squash) only some of the commits, then you need to use git rebase -i or cherry-pick/squash manually each commit.

Stanislav Bashkyrtsev
  • 14,470
  • 7
  • 42
  • 45
  • Stanislav, `master` is not used at all. The master branch would be `release/2.0`. So with that said, are you saying do a `git merge origin/release/2.0`? `feature/DCMP-959` was branched off `release/2.0` for me to make the changes and then create a PR to merge them back with the new branch changes, makes sense? – Daniel Jul 09 '19 at 02:37
  • Whatever branch you intend to merge into – Stanislav Bashkyrtsev Jul 09 '19 at 02:38
  • Stanislav, I am getting `✗ git merge origin/release/2.0 error: Merging is not possible because you have unmerged files.` – Daniel Jul 09 '19 at 02:39
  • You need to resolve all merge conflicts and `git add` those files that had conflicts. Those conflicts were probably unresolved from your previous merge. – Stanislav Bashkyrtsev Jul 09 '19 at 02:40
  • Stanislav, everytime I resolve the merge conflicts and git add and commit and push, the build fails again and when I try to revert, I get the same conflicts again. What is going on? – Daniel Jul 09 '19 at 03:21
  • 1
    So in your remote branch you have only 1 commit that's different compared to your release branch? The error message above says that DCMP-959 task either doesn't exist, or is not in progress or something else. So I guess you'll need to change something about the task in JIRA. – Stanislav Bashkyrtsev Jul 09 '19 at 03:27
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/196169/discussion-between-daniel-and-stanislav-bashkyrtsev). – Daniel Jul 09 '19 at 03:31