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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

Edited

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

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
Community showcase
Published in Bitbucket

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

3,749 views 10 16
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you