In this scenario, a Git Repo has been exported, and the contents of the repo deployed onto an environment.
This deployment does not have any knowledge of Git.
Initialise a new git repo, so any changes can be tracked.
git init
git add .
git commit -am "initial commit"
You can now make your changes, then we commit them as usual. Let's say we make 2 commits for this patch.
echo 'hello world' > test-file
git add test-file
git commit -m "test commit"
echo 'some test' > another-test-file
git add another-test-file
git commit -m "added another file"
Then we create the patches for these 2 commits
git format-patch -2
This will create 2 patch files.
Copy the patch files onto the machine with your actual git repo, then apply them like this
git apply 0001-test-commit.patch
git diff # review changes
git add test-file
git commit -m "applied patch commit 1"
git apply 0002-added-another-file.patch
git diff # review changes
git add another-test-file
git commit -m "applied patch commit 2"
I am going to try this and I hope this helps some people.
I made a folder with a simple README.md. I made the changes above
After initializing the repository I change the root branch from master to main.
Here is the git CLI and a folder where I was just after the step "git format-patch -2"
![image](https://user-images.githubusercontent.com/5836181/284962531-f6543fa2-e9d6-4e3b-9da1-a3e807add758.png)
![image](https://user-images.githubusercontent.com/5836181/284961948-6a3590a0-2bb6-4ceb-a9bb-0419e7b99942.png)
Here is the text of the patch file: 0001-test-commit.patch
![image](https://user-images.githubusercontent.com/5836181/284962209-a610a0fa-abda-4715-8154-fd175c7167de.png)
Here is the text of the patch file: 0002-added-another-file.patch
![image](https://user-images.githubusercontent.com/5836181/284962396-c2845445-ac66-41ae-98f4-39d78ea8e338.png)
Here is the git status in the CLI
![image](https://user-images.githubusercontent.com/5836181/284963520-b9ab13cd-f59c-4356-86f3-d579a010ecc4.png)
I applied the first patch with:
I got an error
![image](https://user-images.githubusercontent.com/5836181/284963823-2cdf0f64-0811-4b3e-984c-0054cd9bcabe.png)
Trying just the line "git apply 0001-test-commit.patch" produces the error.
![image](https://user-images.githubusercontent.com/5836181/284964693-be818cb2-d58b-48dd-86d1-d232ae8f0152.png)