Search code examples
gitversion-controlgit-diff

Git - How to generate a commit from git diff


I am in main branch and there are some mismatches in main and dev. I can see the diff in a specific folder using,

git diff main..dev Code/Folder/*

Now I want to move all the changes the diff showing inside the Code/Folder/* into a new commit in current branch, main.

How do I do that?


Solution

  • Below code works fine (adding changes into main from dev),

    git checkout main
    git diff main..dev Code/Folder/* | git apply
    git add *
    git commit -s -m "Adding diffs to main from dev for Code/Folder/*"