Skip to content

Instantly share code, notes, and snippets.

@evaldasg
Created August 22, 2024 06:41
Show Gist options
  • Save evaldasg/888d382ecbf0e671b085927f4c27b031 to your computer and use it in GitHub Desktop.
Save evaldasg/888d382ecbf0e671b085927f4c27b031 to your computer and use it in GitHub Desktop.
Git diff apply

To pick up changes from one branch and apply them to another branch without using git cherry-pick or any commit-related commands, you can use the git diff and git apply commands. Here’s a step-by-step guide on how to do this:

  1. Switch to the branch with the changes:

    git checkout branch-with-changes
  2. Generate the diff file:

    git diff > changes.diff

    This command will create a file named changes.diff containing all the changes between the current branch and its base.

  3. Switch to the target branch:

    git checkout target-branch
  4. Apply the diff file:

    git apply changes.diff

    This command will apply the changes from the changes.diff file to the current working directory.

  5. Review the changes: You can use git status and git diff to review the changes that have been applied to ensure everything looks correct.

  6. Stage the changes:

    git add .
  7. Commit the changes:

    git commit -m "Applied changes from branch-with-changes"

By following these steps, you can transfer changes from one branch to another without using git cherry-pick or directly dealing with commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment