Submitting multiple pull requests in a row causes commits to be added to the same PR

1.  Introduction

So, I was working on a feature branch of a forked repository and was about to push that branch in order to create a pull request out of it.

I develop my changes, test, commit, push the branch and create a PR.

2. Situation

However, while working on the fore-mentioned feature branch, I also noticed that another PR was needed. I’m working with IntelliJ, so, I at some point noticed that the git ignore file of the project didn’t include any mention to specific IDE-generated files

https://gyazo.com/e3fabc1617693fd2ce18d8b8eda7bbe4

3. Problem

Ok, cool, so, I have to create a new PR, cuz it’s about something totally different.

So, checked out a new branch, committed the changes, pushed the branch and…

https://gyazo.com/f95765dca77645b044ca2faf350ad1e9

What? Why my newly pushed branch is 2 commits ahead of master? I just pushed one commit!

Side note here is that if I create a new PR based on this branch, the changes of my first PR would still be included. So, I have to somehow remove them, synchronize my gitignore-branch with master and then push the branch again, by erasing the previously logged history.

4. Solution

Oke, lemme check:

https://gyazo.com/70a546b0930a6daae6f519e65cbffc0f

Pooooh, of course, when I checked out to a new branch, I have already pushed my first branch, so the newly created branch has on top of its HEAD the latest “local” changes. Let’s reset it back to a valid remote state. That is, just after cloning it:

https://gyazo.com/822ed7d3622bd5215f0435985c24da2d

I’m on the branch which has to do with the update of the .gitignore file, so I only wanna add the .gitignore file ot it and then force the push, so that I erase all the previously existing history of the tree and have a single commit displayed to my branch ( and my PR, of course):
https://gyazo.com/ad89906adea69dfa47e02559f3425535

5. Confirmation

Cool!
https://gyazo.com/482c1e450dddaf55e4fd1f874a680a4e

Cheers!

Advertisements

Beautify your git history by rebasing

1. Introduction

percircle is a project I started on 2015, without having a clue about js (which is still valid :-P), but of course, there’s always place for improvement.

Today I noticed that I was creating a dirty history with several small unnecessary commits, so, I thought about experimenting a bit.

2. Situation

Below you can see a not-so-nice history of 4 commits. What they actually are about is 2 commits for the readme file and a corresponding release to npm for each one of them. But those two changes could be displayed as one, since only the latest is the one that contains the proper changes. So, I wanna somehow erase commits f13df6d and 12632de.

https://gyazo.com/c08dce9412e75485247ad525dc4f0fb8

3. Solution

For this, I will be needing the help of git rebase. Specifically, I wanna rebase on top of the latest release, prior to any changes in the readme file. That is, the commit for November 3:

git rebase -i e1a7e698d399b51cfd2cf283e0ff25d8aa23175c

I then just “drop” the commits that I don’t wanna be included in my history anymore and totally be deleted:

https://gyazo.com/0837b44edb3f7b9988231c5be3c45eac

I save the file and I see that there’s an issue:

https://gyazo.com/8fd7d8f1f5a269123c84c8b436523572

Hmmm, let’s see what is it about:

https://gyazo.com/623f0a0140fa5aff5ad0c4241ee5c286

Ok, let’s go heck what is wrong with this version (I suspect it has to do with versioning):

https://gyazo.com/2d557df4369cdfadc8bdd66f0d053722

Indeed. Ok, lemme:

  • keep the proper version
  • resolve the conflict
  • continue rebasing and
  • force the push

https://gyazo.com/2b99b52a3d4d30be5c43ef4b1f7e51b5

The most important part of such a rebase is to eventually force the push, so that a rewrite occurs in the history’s tree.

4. Result

Yes!

https://gyazo.com/b4a1d69e137e6f9afae6e3f1837474bb

Happy King’s Day!