The git patches can be used as a replacement of react-native-git-upgrade
. The procedure is
straightforward and more trusted than using the upgrade command.
Check the diff of your current version and the release you want to upgrade to.
Do the changes from the diff in your project.
They are usually no more than 10 lines, so it's pretty quick and easy.
If it's more than that, you could try the alternative method below.
Download the patch for your version, for example:
curl https://github.com/react-native-community/rn-diff-purge/compare/release/0.29.0...release/0.30.0.diff > upgrade-rn.patch
The patch is made for the RnDiffApp located in the RnDiffApp folder of this repository. To use it in your own repository, some changes are needed.
Don't worry about the root folder RnDiffApp, it can be ignored with the option -p 2
(see https://git-scm.com/docs/git-apply)
Then, some files include the name of the app in their path:
- All files in the
ios
directory (example:ios/RnDiffApp/AppDelegate.m
) - Some files in the
android
directory (example:android/app/src/main/java/com/rndiffapp/MainActivity.java
)
You have to edit the patch and replace all occurences of ios/RnDiffApp
and com/rndiffapp
by the name of your app.
By default in case of conflicts, the git apply
command will fail and leave the files untouched.
It could be interesting to fallback on a 3-way merge (option --3way
) in order to resolve the
conflicts with your favorite merge tool.
To do this, git needs to know the blob referenced in the patch
(line index 4c88077..e49e881 100644
for example). So you have to add rn-diff as a remote
repository and fetch it (see this SO question
for details).
git remote add rn-diff-purge https://github.com/react-native-community/rn-diff-purge.git
git fetch rn-diff-purge
git apply upgrade-rn.patch --exclude=package.json -p 2 --3way
# Download the patch
curl https://github.com/react-native-community/rn-diff-purge/compare/release/0.29.0...release/0.30.0.diff > upgrade-rn.patch
# Replace RnDiffApp occurences
appNameCamelCase=MyApp
appNameLowerCase=myapp
sed -i "" "s-ios/RnDiffApp-ios/${appNameCamelCase}-" upgrade-rn.patch
sed -i "" "s-java/com/rndiffapp-java/com/${appNameLowerCase}-" upgrade-rn.patch
# Set up the 3-way merge
git remote add rn-diff-purge https://github.com/react-native-community/rn-diff-purge.git
git fetch rn-diff-purge
# Run the apply command
git apply upgrade-rn.patch --exclude=package.json -p 2 --3way
Sometimes there are new files that reference the project's name. Whenever there is a new file, make sure to check for this, and replace it with your project's name.