CodeRef
CodeRef
  • Software
    • VSCode
  • Midjourney_AI
    • Midjourney Cheat Sheet
  • aws
    • S3 Reference
    • Services
  • bash
    • .bashrc File Contents
    • CAN
    • _System Config File Locations
    • argument-length-limits
    • Conditionals
    • Data Structures
    • File Permissions
    • File Syncing
    • File System
    • Functions
    • General
    • Loops
    • My Functions
    • Networking
    • Number Operations
    • OpenVPN
    • Operators
    • Resource Management
    • Serial RS232
    • Spinning Wheel Animation
    • SSH
    • Text Operations
    • Environment Variables
  • cpp
    • ChatGPT | Pointers vs. References
    • arrays
    • Classes
    • Data Types / Structures
    • Enumerated Classes
    • Exception Handling
    • Function Objects
    • Functions
    • I/O
    • Loops
    • Macros
    • Namespaces
    • New Features
    • Pointers
    • Scope
    • Smart Pointers
    • Raw String Literals
    • Style Guide
    • Switch Case
    • Templating
    • How to Use tinyxml2
    • Useful Libraries
    • google-test
    • Conditionals
    • Rule of Three/Five
    • Optional Parameters
    • Keywords
    • Filesystem
    • Random
    • Casting
    • tools
  • git
    • Code Review Dependency Strategy
    • Git Bisect Guide
    • Git Reference
    • removing-cherry-picks
    • Useful Tools
    • Graphite Reference
  • js
    • functions
    • Javascript Reference
  • linux
    • Display
    • Dual Boot with Windows
    • File System
    • NVIDIA
    • Sending/Receiving TCP/UDP Messages in Ubuntu
    • dynamically_linked_binaries
  • markdown
    • Images
    • obsidian-reference
  • python
    • Classes
    • Exceptions
    • Functions
    • Operations
    • Python Reference
    • unittest_command-line-args
    • unittest_magicmock_GPT
    • unittest_mock
    • unittest_printing
    • unittest_subtest
    • useful-stuff
    • jupyter
    • poetry
  • ros
    • _ROS Cheat Sheet
    • Create New Workspace
    • Install ROS
    • Node Sample - Listener
    • Node Sample - Talker
    • Node Template
    • Setup
    • urdf
  • excel
    • excel-reference
  • windows
    • File System
    • WSL - Windows Subsystem for Linux
    • WSL
  • software_engineering
    • uncle_bob_lectures
      • Overview
      • Lesson 01 - Notes
  • web
    • Front End
    • Hugo
    • new_frontend_tools
  • sql
    • cheatsheet
Powered by GitBook
On this page
  1. git

removing-cherry-picks

How to remove cherry-picked commits from a branch.

From Bard.

Ah, I understand now. Since you made changes and committed them after the cherry-pick, removing the cherry-picked commit directly becomes more complex. Here are some options you can consider:

1. git revert with interactive staging:

This approach allows you to selectively undo changes introduced by the cherry-picked commit while keeping your own changes.

  • Run git revert <cherry-pick-commit-hash>.

  • When prompted to stage changes, you can choose which lines/sections to revert from the cherry-picked commit while keeping your own modifications.

  • This offers more control over what gets reverted.

2. Create a new branch:

  • Create a new branch from the state before the cherry-pick.

  • Cherry-pick your desired changes onto this new branch.

  • Discard the original branch with the unwanted cherry-pick.

  • This preserves the original branch history while incorporating your desired changes in a new branch.

3. Rebase (advanced):

  • This is a more advanced option that rewrites history. Use it with caution and ensure you understand its implications.

  • Use git rebase -i <branch-name> to interactively edit the commit history.

  • In the editor, mark the cherry-pick commit for "drop" and save the changes.

  • This will rewrite history, removing the cherry-pick commit but also potentially affecting other commits depending on your branch structure.

4. Manually revert changes:

  • If the cherry-pick introduced a small number of changes, you can manually revert them by editing the relevant files and committing the changes.

  • This might be time-consuming but offers fine-grained control over what gets undone.

Important notes:

  • Testing: Regardless of the method, ensure you have tested your changes and have backups before proceeding.

  • History: Each approach affects branch history differently. Choose the one that best aligns with your needs and preferences.

  • Collaboration: If working in a team, communicate your actions and use methods less likely to disrupt shared history (e.g., new branch or interactive revert).

Remember, the best approach depends on your specific situation and comfort level with Git commands. If unsure, consider consulting online resources, documentation, or seeking help from experienced Git users.

Last updated 1 year ago