Forked from zilongshanren/git-export-changes-between-two-commits.md
Created
March 2, 2025 17:28
-
-
Save truyenpt/ed85de1ea37b34d9620146edd6fc7b2e to your computer and use it in GitHub Desktop.
Revisions
-
mrkpatchaa revised this gist
May 10, 2017 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -34,9 +34,11 @@ git am *.patch --reject Errors : ``` The copy of the patch that failed is found in: .git/rebase-apply/patch ``` ``` pathspec '0001-add-contributing-to-the-components-generator-guide.patch' did not match any files ``` ``` Rejected hunk #1. ``` -
mrkpatchaa created this gist
May 10, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,66 @@ **Use case :** Imagine we have just created a project with `composer create-project awesone-project` (currently **V0.2**). 2 weeks later, there is a new release (**V0.3**). How to update your project ? Since `composer update` only updates the project dependencies, it is not what we are looking for. Composer doesn't know about awesome-project since it's not in our **composer.json**. After trying many git solutions, I've come to this : `git archive --output=changes.zip HEAD $(git diff --name-only SHA1 SHA2 --diff-filter=ACMRTUXB)` This command will check for changes between the two commits and ignore deleted files. And after checking, it will copy those files into an archive. So you must `git clone awesome-project` before doing this. `git diff --name-status SHA1 SHA2 | grep "D\t"` This one will show you deleted files between the 2 commits, to help applying changes to your project. After deleting files, you can unzip *changes.zip* and run `\cp -rf ../changes/* .` from your project directory to update your project with modified files. **PS :** Some files could not be present in the latest commit. So you can first run `git checkout SHA1` before running theses commands. Inspired of https://gist.github.com/betweenbrain/2284129 ### **Other solutions tried** * Git Patch ```git clone https://github.com/awesome/project.git cd project git format-patch SHA1~..SHA2` cd ../my-project git am *.patch --reject ``` Errors : ``` The copy of the patch that failed is found in: .git/rebase-apply/patch pathspec '0001-add-contributing-to-the-components-generator-guide.patch' did not match any files Rejected hunk #1. ``` Nope : `git am --abort` * Git pull from remote origin and merge ``` git remote add awesome-project https://github.com/awesome/project.git git remote update git tag -l git checkout tags/v4.1.0 new-branch git branch -f master new-branch git checkout master Switched to branch 'master' Your branch and 'origin/master' have diverged, and have 1298 and 3 different commits each, respectively. (use "git pull" to merge the remote branch into yours) ``` I've just added 1300 commits to my git history ... Nope ``` git branch -D new-branch git reset --hard origin/master git remote rm awesome-project git remote update ```