Eridian
eridian.xyzx.comGitHub
  • 📖Eridian Docs
  • Ethereum Dev
    • ✏️Ethereum Notes
      • 🎛️Technical Basics
      • 🪧Ethereum Addresses
      • 📚Ethereum State Explained
      • ⛽Gas Fees Explained
    • 🔧Useful Tools
      • ☁️Ethers
      • *️⃣Ethernal
    • 📝Solidity Notes
      • ❔Interview Questions
        • 🟢1. Easy - Interview Questions
        • 🟠2. Medium - Interview Questions
        • 🟡3. Hard - Interview Questions
        • 🔴4. Advanced - Interview Questions
      • 💡Note Ideas
      • ABI
      • abi.encodePacked
      • Abstract Contracts
      • Arrays
      • Casting
      • CEI - Checks, Effects, Interactions
      • Comments (NATSPEC)
      • Constructor
      • Contract Structure & Versions
      • Data - Storage vs Memory
      • Data - Storage Layout
      • Enum
      • Errors (require & revert)
      • Events
      • EVM Opcodes
      • External Contract Interaction
      • 🏗️External Dependencies
      • Functions
      • Function Modifiers
      • If / Else / For / While Loops
      • Inheritance
      • Interfaces
      • Keccak256
      • Library
      • Mappings
      • msg.sender
      • Objects & Types
      • OpenZeppelin
      • Payable
      • Public State Variable vs Function
      • Receive & Fallback
      • Security
      • Self Destruct
      • Send ETH (transfer, send, call)
      • Stack Too Deep
      • Structs
      • Style Guide
      • Time Units
      • Try / Catch
      • Typecasting
      • Using Directive
      • Variables, Consts & Immutable
      • Withdraws
    • ⚒️Foundry Notes
      • 📖Docs & GitHub Pages
      • 🤝Useful Commands
        • 🔨Anvil
        • 🪄Cast
        • 🔥Forge
      • 🧪Tests
        • Cheatcodes
      • 📝Useful Scripts
        • Deploy Contract Using Hex
    • 👾DeFi Challenges
      • 👨‍🚀Ethernaut
        • Ethernaut - Template
        • Level 1 - Fallback ⏺
        • Level 2 - Fallout ⏺
        • Level 3 - Coin Flip ⏺⏺
        • Level 4 - Telephone ⏺
        • Level 5 - Token ⏺⏺
        • Level 6 - Delegation ⏺⏺
        • Level 7 - Force ⏺⏺⏺
        • Level 8 - Vault ⏺⏺
        • Level 9 - King ⏺⏺⏺
        • Level 10 - Re-entrancy ⏺⏺⏺
        • Level 11 - Elevator ⏺⏺
        • Level 12 - Privacy ⏺⏺⏺
        • Level 13 - Gatekeeper 1 ⏺⏺⏺⏺
        • Level 14 - Gatekeeper 2 ⏺⏺⏺
        • Level 15 - Naught Coin ⏺⏺⏺
        • Level 16 - Preservation ⏺⏺⏺⏺
        • Level 17 - Recovery ⏺⏺⏺
        • Level 18 - Magic Number ⏺⏺⏺
        • Level 19 - Alien Codex ⏺⏺⏺⏺
        • Level 20 - Denial ⏺⏺⏺
        • Level 21 - Shop ⏺⏺
        • Level 22 - Dex ⏺⏺
        • Level 23 - Dex Two ⏺⏺
        • Level 24 - Puzzle Wallet ⏺⏺⏺⏺
        • Level 25 - Motorbike ⏺⏺⏺
        • Level 26 - DoubleEntryPoint ⏺⏺
        • Level 27 - Good Samaritan ⏺⏺⏺
        • Level 28 - Gatekeeper 3 ⏺⏺⏺
        • Level 29 - Switch ⏺⏺⏺⏺
        • Level 30 - Higher Order ⏺⏺⏺⏺
        • Level 31 - Stake ⏺⏺⏺
      • 💸Damn Vulnerable DeFi
    • 🔍Auditing
      • 🗞️Exploit Resources
      • 🔧Audit Tools
    • 🤖MEV
  • Infrastructure Docs
    • 💻Hardware
    • 🐧Linux
      • 📖Linux Glossary
      • ⌨️Linux Commands
      • 💾Installation
      • 🏗️Maintenance
      • 🖥️Ubuntu Desktop
      • 🛜ZeroTier
      • 🎞️TMUX
      • 🔵Bluetooth
    • ⛓️Ethereum Clients
      • ⚙️Execution Clients
        • ⛏️Geth
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
        • 🐻Erigon
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
        • 🧶Besu
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
      • 🤝Beacon Clients
        • 💡Lighthouse
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
        • 🪅Teku
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
      • 💎Validator Clients
        • 💡Lighthouse
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
      • ➕L2 Clients
        • 🔵Base
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
      • 💰MEV Boost
        • 💾Installation
        • 🏗️Maintenance
    • 🚨Alerting and Monitoring
      • 🔥Prometheus
      • 🌡️HealthChecks.io
      • 📟PagerDuty
  • General Dev
    • 💾Git Notes
      • Repos
      • Committing changes
      • Branches
      • Merging & Rebasing
      • PRs
Powered by GitBook
On this page
  • Merge Example
  • Rebase Example
  • Reversing Changes
  • Moving things around
  • Git Tags
  • Fetch Arguments Example
Edit on GitHub
  1. General Dev
  2. Git Notes

Merging & Rebasing

Last updated 2 months ago

  • So do you rebase, then merge? It looks like rebase just makes changes?

Description
Commands

Merge two branches

  • The branch name used should be the one you are not currently in

git merge <BRANCH_NAME>

Rebase one branch onto another

  • If you are currently on a branch, you can rebase to move all of the commits in that branch to a new attachment point on a different/new branch

  • In the example below, main* was on C3 and the command git rebase C2 was used to rebase/move C3 to after C2

  • This changes the "base" so that it looks like the features were developed sequentially rather than in parallel

  • This makes the git diagram neater

git rebase <BRANCH_NAME/REF> git rebase <REF1> <REF2>

Completely replace Main with a Branch

git checkout main

git pull

git checkout <BRANCH>

git merge -s ours main

git checkout main

git merge <BRANCH>

Merge Example

git checkout main
git pull
git merge side1
git merge side2
git merge side3
git push

Rebase Example

git fetch
git rebase o/main side1
git rebase side1 side2
git rebase side2 side3
git rebase side3 main
git push

Reversing Changes

Description
Commands

Reverses changes by moving a branch reference backwards in time to an older commit

  • In this sense you can think of it as "rewriting history"

  • git reset will move a branch backwards as if the commit had never been made in the first place

  • --hard deletes commits between current location and the reference used so they are no longer in the history

git reset <REF>

git reset HEAD^

git reset --hard HEAD^

While resetting works great for local branches on your own machine, its method of "rewriting history" doesn't work for remote branches that others are using.

  • In order to reverse changes and share those reversed changes with others, we need to use git revert

git revert <REF>

git revert HEAD

Moving things around

Description
Commands

Copy a series of commits below your current location (HEAD)

  • Think of cherry-pick like a rebase where the commits added before the current location are specifically selected

  • Sure, you can also do some specific selection with git rebase -i but that is only commits in the selected path, cherry-pick commits could come from anywhere

git cherry-pick <COMMIT_1> <COMMIT_2> <...>

Git Interactive Rebase

  • Using the rebase command with the -i option

  • If you include this option, git will open up an editor to show you which commits are about to be copied below the target of the rebase. It also shows their commit hashes and messages, which is great for getting a bearing on what's what.

  • It seems to open in vim

git rebase -i <REF>

git rebase -i HEAD~4

Git Tags

Description
Commands

Add a tag

git tag <TAG_NAME> <REF>

git tag 1.0.0 main

Checkout a tag

git checkout <TAG_NAME>

Push tags to remote

git push <REMOTE_NAME> --tags

Describe where you currently are relative to the closest "anchor" (aka tag)

  • If you don't specify a <REF> the git will just use where you're checked out right now (head)

  • Where <TAG> is the closest ancestor tag in history, <NUM_COMMITS> is how many commits away that tag is, and <CURRENT_HASH> is the hash of the commit being described.

git describe <REF>

OUTPUTS:

<TAG>_<NUM_COMMITS>_g<CURRENT_HASH>

Fetch Arguments Example

git fetch origin foo:main
git fetch main^ origin:foo
git checkout foo
git merge main

💾
https://learngitbranching.js.org
https://learngitbranching.js.org