How to revert changes to deleted and then recreated file in git branch? I want these changes not to appear in git diff
with main
branch I've diverged from.
My steps were the following:
- diverged from
main
branch to branchtest
- deleted file
src/patches/axios.patch
(not actual name, I'm usingpatch-package
npm package so names are correct in my project for sure) - committed change and pushed to remote
- generated new patch for
axios
with same name in other place (axios.patch
) - copied new patch from step 4 to
src/patches
asaxios.patch
- committed changes and pushed to remote
- now in Github PR page I see same file deleted and same file added
I know that I can revert a file to some specific state at some specific commit. In my case it would be main
branch state when I've diverged from it ( if file changed in meanwhile )?
I've also checked git diff main
on my branch and there are these changes also present, so it's not Github UI glitch:
diff --git a/src/patches/axios.patch b/src/patches/axios.patch
deleted file mode 120000
index fcc8ab7fb..000000000
--- a/src/patches/axios.patch
/dev/null
@@ -1 0,0 @@
-../../patches/axios.patch
\ No newline at end of file
diff --git a/src/patches/axios.patch b/src/patches/axios.patch
new file mode 100644
index 000000000..fcc8ab7fb
--- /dev/null
b/src/patches/axios.patch
@@ -0,0 1 @@
../../patches/axios.patch
\ No newline at end of file
CodePudding user response:
When you added the file you did not just undo an earlier removal. Notice these two lines in the provided output:
deleted file mode 120000
and
new file mode 100644
They mean that you deleted a symbolic link and added a regular file.
To undo the earlier removal, you really have to use
git checkout -f main -- src/patches/axios.patch
(Modern Git has git restore
to do the same thing, but I do not know how to operate it---I'm an old-timer.)