Where It All Started.

Where It All Started.

Life, Stock Trading, Investments, Business and Startup. Most are programming stuff.

Rebasing With Git

Rebasing is one of the features you probably want to have, if you plan to work on a neat git based project.


๐Ÿฃ Where To Rebase?

If you know how many commits you make, to rebase you use git rebase with -i flag to enable interactive rebasing. The HEAD~<n> corresponds to the number of commits you have done (e.g. HEAD~4 if you have 4 commits to rollback to get to common ancestor commit).

git rebase -i HEAD~<n>

Sometimes, you commit a lot and forgot how many commits youโ€™d make. To know the least common anscestor you have with master, you do git merge-base with your branch name as parameter.

git merge-base <your-branch> master

The above command will return a git hash which you can use on the git rebase command.

If you already know the git hash, then you can rollback to that specific commit and moving all current changes to unstaged. Once, the editor pop-ups you will choose which commit to retain, squash, and reword.

git rebase -i <git-ref-hash>

๐Ÿฃ Merge Latest From Master

If youโ€™ve already rebased your changes and needed to get lastest changes from master. All you have to do is rebase to the latest changes from master.
This command will do that.

git rebase origin/master

In any case, youโ€™ve encountered some conflict first resolve it then continue in rebasing instead of creating new merge commit.

git rebase --continue

๐Ÿฃ Overwriting Remote Repo Changes

Once all is done, overwrite your remote repo latest changes if youโ€™ve pushed it. This will do a force push ignoring current ref on remote repo.

git push -f

๐Ÿฃ Did Something Wrong? In Need Of Rollback

Did something wrong on merging conflicts? Donโ€™t worry you can still see your previous changes using the command git reflog short for reference log.
You can checkout the reference hash then re-merge your changes.

git reflog

References

Popular Posts

  • Bitcoin (BTC) Still Bullish According To BlockTower
    The continuous Bitcoin volatility, according to BlockTower Capital’s general partner Michael Bucella, should not come as a surprise because it is part of the asset’s development trajectory. Bucella told CNBC […]
  • Major Firm BlackRock To Create It’s Own Blockchain ETF
    According to a filing with the US Securities and Exchange Commission on Jan. 21, BlackRock Inc., the world’s largest asset management business, has applied for an exchange-traded fund (ETF) that […]
  • Google Going Crypto
    As the firm looks to provide a wider range of financial services, including cryptocurrencies, Google has hired veteran PayPal CEO Arnold Goldberg to manage its payments division. Google’s action comes […]
  • Total Crypto Market Cap Will Reach 5 Trillion USD In 2022 According To AvaLabs CEO
    In 2022, John Wu, the CEO of Ava Labs, a blockchain business that creates the software for the Avalanche (AVAX) blockchain, offered a lot of fascinating forecasts for the cryptocurrency […]
  • Pavia Metaverse Project Debuts On Cardano (ADA)
    The Metaverse is currently in its early stages. While Ethereum-based metaverse games like The Sandbox have exploded in popularity, investors are also interested in developing applications on secure PoS networks […]

Leave a Reply

Your email address will not be published. Required fields are marked *