I am trying to move uncommited changes from a local git repository to another local repository. On repo 1 I create a patch like this:
git diff > my_patch.patch
Inspecting the patch:
more my_patch.patch
I get the same output as running git diff on the first repo.
In the second repo I run:
git apply --stat my_patch.patch
0 files changed
If I run git apply my_patch.patch I get no effect.
Am I creating the patch wrong? Am I applying it wrong?
Steps to reproduce the issue:
- Clone a repository 2 times (same branch checkout)
- In first repo, make some changes to a file (uncommited).
- Create patch from changes:
git diff > ~/my_patch.patch - Go to second repository. Try and apply patch:
git apply ~/my_patch.patch - Run
git status. No changes!
Suggesting another way of moving uncommited changes to another local repo would also be good to solve my issue.
Not only your usecase now (Q4 2021, Git 2.34+) is working as expected, but Git 2.35 (Q1 2022), "
git apply"(man) has also been taught to ignore a message without a patch with the--allow-emptyoption.And it learned to honor the
--quietoption given from the command line.See commit 324eb77, commit c21b8ae (13 Dec 2021) by Jerry Zhang (
jerry-skydio).(Merged by Junio C Hamano --
gitster-- in commit 62a3a27, 22 Dec 2021)git applynow includes in its man page:git applynow includes in its man page: