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
- Git Patch
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
Tremendous! This is exactly what I needed. Thank you.