1

I deleted some files in my local and i shouldn't push these changes. Now i want these changes in the local when i switch the branch. Is there a way to do that.

I tried git stash and git pop. But this should be done everytime i do a switch between branches. Is there a command to make it simple.

santosh
  • 21
  • 4
  • What is your use case/could you give a clearer picture or example of what you're trying to do? It seems to me as though you could create another local branch to save all your changes, which won't affect the main branch. However, this depends on what your use case is. – thevioletsaber Oct 21 '19 at 04:31

1 Answers1

0

If those files were tracked before their removal, you can restore them with the new (Git 2.23+) command git restore (man page)

Find first the last commit where your file was deleted

git rev-list -n 1 HEAD -- [file_path]

That gives you '', a SHA1 commit reference.

Then restore it:

git restore --source <sha>~ Makefile
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250