how to recover accidently deleted file

I was about to commit a file . But i accidentally deleted that file. How can i recover it. It was very important file because it was controller file

2 answers

Where did you delete the file? In your local environment? If so, this question has nothing to do with Bitbucket server and the answer to your question is to check if your environment keeps deleted files somewhere or if you have backups.

The other side of the question here is if you have deleted a file that is already in git which the answer is easy since it's already in version control and the internet is full of answers about it.

As Gabrielle Bautista says, if you never committed the file, then you need to recover it like you would any other deleted file on your workstation, such as pulling it out of the trashcan or recycling bin or what not or recovering it from backups.

If you did previously commit the file, the above might still be your best option to recover any changes you've made to it since commit.  But you can at least definitely retrieve it from the previous commit using 

git checkout <branch_name_or_commit_id> <file_name>

Assuming you're working on the master branch, haven't committed since the last commit that contained the file, and the file was named foo.bar, it would be like this:

git checkout master foo.bar

 

 

 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jun 06, 2018 in Bitbucket

Do you use Bitbucket Cloud and Jira Cloud? If so, let us know!

Hi Community, I'm Julia and I'm on the Jira Software Cloud marketing team!  We're looking for companies or teams using Bitbucket Cloud and Jira Software Cloud. If your team fits the t...

171 views 6 3
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you