2

I'm trying to get the previous version of a file like this:

git checkout <git-hash>

After this, I see that the file on my hd is the previous version. How can I push this version to the server??? I tried the following:

git push ab master

but all I get is

Everything up-to-date

What am I doing wrong?


When i do

git checkout 123456 -- src/test.c

git commit -m "Bringing back test.c from commit 123456"

I get

Not currentyly on any branch

123456 is hash

Kev
  • 118,037
  • 53
  • 300
  • 385
user681598
  • 23
  • 2

3 Answers3

2

I'm assuming that 123456 is the name of an old commit, not the name of a file - it's not clear from the question, as Ben Hocking points out.

When you push, you push a complete commit (which defines the complete state of a tree) rather than individual files. The git push ab master command is the same as git push ab master:master, which means "update master on the remote ab with my version of master". The error "Everything up-to-date" is telling you that all of the history of your master branch is already contained in the remote master branch.

Instead, you'll need to create a new commit with the old version of that file instead. You can do this with:

# Make sure that you're back on the master branch first:
git checkout master 

git checkout 123456 -- src/test.c
git commit -m "Bringing back test.c from commit 123456"
git push ab master
Community
  • 1
  • 1
Mark Longair
  • 446,582
  • 72
  • 411
  • 327
2

When you do:

git checkout 123456 

you are now in a "detached HEAD" mode, meaning any modification you make aren't referenced by HEAD.
That explains why git push says "Everything up-to-date": you aren't in any branch, so you didn't make any modifications to be pushed.

But if you follow Mark's advice and do:

git checkout 123456 -- src/test.c

You modify only the the working tree for a given file, but you are still in your current branch.
src/test.c will be modified, you can then add it, and commit, moving HEAD of your current branch.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

Is 123456 your file name or your commit hash#? Since you didn't provide a file name, I'm guessing it's a file name, which means that you checked out the version that was last committed. Assuming that commit had already been pushed, it would seem logical that everything would be up to date.

Ben Hocking
  • 7,790
  • 5
  • 37
  • 52