Reputation: 121
I've two servers - Staging and Live. I keep my staging server up-to-date so it has all the latest changes push to my git repo. Now I want to update my Live server but I don't want to pull everything from my repo but only till a specific commit.
When I do
git status
it says
# git status
# On branch master
# Your branch is ahead of 'origin/master' by 21 commits.
#
When I do
git checkout 7c7f78382fgh9e642d9b3298acacc5903410fefa
I get an error...
fatal: reference is not a tree: 7c7f78382fgh9e642d9b3298acacc5903410fefa
Any idea what can be wrong.
Do I need to pull everything latest and then do checkout ?
Thanks!
Upvotes: 5
Views: 8368
Reputation: 3116
To be clearer, you should actually check out a hash to a branch, otherwise you'll be in a detached head state.
git fetch origin # Fetches commits from the remote repository
git checkout -b new_branch_name 7c7f783 # creates a new branch from this commit.
Upvotes: 4
Reputation: 2894
You need to fetch the remote commits before you can use them.
On your production server:
git fetch origin # Fetches commits from the remote repository
git checkout 7c7f78382fgh9e642d9b3298acacc5903410fefa # Moves forward to the relevant one
Upvotes: 0