VS-Code - How to put vscode executable in system path and how to open source code directly in vscode
Introduction VS code is an excellent free IDE for maany types of programming…
June 11, 2020
If you working on a github project in a team. Consider you have created a branch from Master branch, and did few commits as we normally do.
When the feature work is done on that branch. You would want to commit that in Master branch. But, when you create a Pull Request (PR) for that merge. Reviewer will see the intermediate commits in your PR. Which might annoy him. And there is no benefit of incorporating that history into Master branch. Although, there is a “Squash and Merge” option. But, anyone can easily forget that because this option is not enabled by default.
So, reviewer would want to cleanup your commit history so that only one commit is visible in the PR.
This post is about create a PR without historical commits. So that, reviewer will only see single commit containing all the file changes.
Apart from git merge, there is a git rebase option too. Git merge and git rebase both are used to integrate your changes into main branch.
# Switch to your feature branch
git checkout FeatureBranch
# in this case, our main branch is master
git rebase master
If there is no conflicts, this will work. Now, you just to push the changes.
git push -f
We will use interactive way of doing git rebase. Interactive rebasing is used to manipulate your history. And we would want to clean up history.
# Switch to your feature branch
git checkout FeatureBranch
# start interactive rebasing
# in this case, our main branch is master
git rebase -i master
This will open up an editor (vim kind) and few options. See example below:
pick 8472as3 add Test bug-1
pick 92731cf add feature description
pick asf4234 bug fix
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
It start with your commits list. Now you have to edit this. Note the default: pick keyword in front of each commits. And, below that there are various options. Now, we want to have all the commits into one. Put pick keyword with only one commit, that will be there in final history. Put squash keyword in-place of pick in front of commits. The file looks like:
pick dae2691 add amazing feature
squash 3491879 add test
squash 3fedbd5 fix typo
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
Save it, and quit editor. On console, it will show some messages. Messages ends with something like:
Successfully rebased and updated refs/heads/FeatureBranch.
Now you have to push your changes. Just run:
git push -f
Now create your PR, and you will see only one commit in history.
If your feature branch is forked from another git repo. Use below commands:
git checkout FeatureBranch
git remote add upstream https://github.com/<main_repo>/PROJECT.git
git rebase -i upstream/<main_branch_name>
# after saving editor content.
git push -f
Note: You might see some conflicts, which you need to resolve before pushing changes.
Assume, You created a branch named: FeatureBranch from Master branch. And you did some commits to it.
Now, create another branch from Master branch. Lets name it:
feature_branch_no_history
Now, You have three branches:
Now, we will do this in two steps:
Note: you will see more than one commits in this process too.
Happy code reviewing. Happy reviewer… Happy Coding…
Introduction VS code is an excellent free IDE for maany types of programming…
Introduction In my previous article, I explained How to have set of fields and…
Introduction I have an automation script, that I want to run on different…
This will take backup of your passed database name, to the passed folder. It…
Many times, while administering your drupal website, you must have encountered…
Introduction In this post, I will show how to validate your json schema…
Introduction In this post we will see following: How to schedule a job on cron…
Introduction There are some cases, where I need another git repository while…
Introduction In this post, we will see how to fetch multiple credentials and…
Introduction I have an automation script, that I want to run on different…
Introduction I had to write a CICD system for one of our project. I had to…
Introduction Java log4j has many ways to initialize and append the desired…