Adding back a file in git which was renamed to a different file name

53 Views Asked by At

I had a file:

a.cs

which I renamed to:

b.cs

and made some logic changes in b.cs

Now I realized I need to re-add a.cs BUT keep b.cs.

I added back a.cs but I don't see it in the working directory and so I can't add it to the staging area and commit.

In the remote, I see that b.cs was renamed.

I assume it's because I renamed the original file instead of deleting it.

I know about the mv command but I don't know how to use it in this specific scenario

So what I need now, if it's possible, is to add back a.cs AND still keep b.cs?

Updated Ok - so this is mistake. The file was added back. Sorry for the confusion.

1

There are 1 best solutions below

0
On

git restore -s <SHA1> -- a.cs

Assuming that a.cs was committed earlier and it's SHA1 can be found in git log.

This will restore the file a.cs to the current working branch.


This is how SHA1 hashes look like a94a8fe5ccb19ba61c4c0873d391e987982fbbd3.