Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

git reset broke my local repo, how to change to (initial) commit?

JR_Atlassian October 4, 2020

Ok, so I have "read the documentation" down before I go making changes so while resetting my master I somehow deleted all the files that I managed to fix after three years... but following this link.

https://community.atlassian.com/t5/Sourcetree-questions/Undo-quot-Reset-current-branch-to-this-commit-quot/qaq-p/340956

I found the 'git reset --hard HEAD@{1}' worked and I have my files back WHEW.

So now I am getting an error

 

"""

On branch master

Your branch and 'origin/master' have diverged,

and have 1 and 1 different commits each, respectively.

  (use "git pull" to merge the remote branch into yours)

 

nothing to commit, working tree clean

"""

When I do a git pull I get 

'fatal: refusing to merge unrelated histories'

My git reflog produces this.

"""

133f131 (HEAD -> master) HEAD@{0}: reset: moving to HEAD@{1}

310786e (origin/master) HEAD@{1}: reset: moving to origin/master

133f131 (HEAD -> master) HEAD@{2}: commit (initial): Elisabeth is working

"""

How do I make sure I save the files I have, then I guess merge them into the repo and finally what "learn git" course would you recommend?

1 answer

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 5, 2020

Hello,

If you have all the files you need locally, you can run git status in your local repo, to see if the changes in these files have been committed or not. If you see in the output nothing to commit, then the changes have been committed, otherwise you can commit any changes you have made so that you don't lose them.

You can take a backup of your local repo by copying the directory of the repo to a different location. If you want to take a backup of your remote repo, before making any changes, you can take a clone with the mirror flag:

git clone --mirror repo_url

The message that you get on pull, 'fatal: refusing to merge unrelated histories', indicates that the local repo and the remote one have unrelated histories and they don't have any common commits. If you still want to pull and merge them, you can run

git pull origin master --allow-unrelated-histories

However, I strongly recommend taking a backup of both repos before you do that, as I suggested above.

We have the following tutorials on Git, which start with the basics and then move to more advances topics:

If you have any questions or need any further help, please feel free to let me know!

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events