Showing posts with label rebase. Show all posts
Showing posts with label rebase. Show all posts

Monday, July 25, 2022

How to remove a wrong commit from the pull request

 $ git checkout pull_request_branch

 $ git rebase -i HEAD~n //n is the number of commits you would like to see during rebase or you could specify the number of commits you have made to the pull request.

3. Replace pick with drop for commits that you want to discard from the PR

Once you are done with the rebase, push forcefully to the remote branch

$git push origin pull_request_branch -f

You are good!


Thursday, September 27, 2018

When to amend/squash commits and how to maintain a clean PR

I always like to improve the development process with the git and a strong believer in the clean code.
Something which I always insist during my PR review is - maintain the clean git history by avoiding the unnecessary indivual commits. 

Broadly, we can follow these 2 rules:

  1. amend/squash commits if they don't add semantic value to the PR
  2. Always rebase the PR before you push to the server

Below article exactly reflects my thought on this.



Other nice articles on this:

https://www.atlassian.com/git/tutorials/rewriting-history
https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History

Wednesday, June 10, 2015

How to rebase your pull request

But, why ?

Your pull request(PR) might be pretty old and in mean time many people would have changed the same code. So you can't simply merge your PR into master branch because of the conflicts.

Step 1:
Fetch the latest code from remote master branch.
> git fetch upstream

here upstream is pointing to a remote repository.

Step 2:
If you have multiple commits, it's better to squash them. But it's an optional step.
>git merge-base <yourforkedbranch> <mainremotebranch>
Example: git merge-base TISTUD-9000 release

This will give the hash-id.
>git rebase --interactive <hash-id>

It will list down the commits, If you have more than one, you can replace 'pick' by 'squash' for commits expect first one.
Example:
pick 4455 
squash 5555
squash 85858

Step 3:
Run rebase command
>git rebase upstream/master

For sure, this will fail because of the conflicts. I mean, that's the main reason why we wanted to go for rebase here.

And once you resolve the conflicts continue with the rebase --continue.

Step 4: 
Update the pull request forcefully
>git push -f

or
> git push origin <yourbranch> -f

This is the crystal clear resource which will talk about this.