Deleted all my commit after bad manipulation in GitHub - github

After a bad manipulation I deleted all the commit of my git.
Can I recover all my commit ?
It's for a university project and the professor wants to see our work throughout the project.
I don't know if my problem become after the command
git pull --rebase origin master
or
git reset --mixed origin/master
or another comand...
Someone can help me please

Check first you git reflog: if your work was committed (before any git pull/reset command), you will be able to git restore (with Git 2.23+) any past commit.
The next step will be to see if you have added files to the index or not.
Anything not staged (added to the index) and not committed would be likely lost (except for disk recovery utilities, or local IDE history)

Related

How to recover lost changes locally

I have a project on GitHub. I made some changes to it and I wanted to apply git push but it showed some error. I googled for solution and someone said to do git stash git pull, so I did those two. In the end all my changes to the projects on my local machine are lost. It became the same project as on GitHub without all the changes.
Tried git fsck --lost-found but didn't work.
git stash saves you changes but resets the state to the last commit. To restore the saved (not commited) changes, simply run git stash apply. (Learn more in the docs.)

Github stuck, can't sync, can't revert

I have a merge remote-tracking branch 'origin/master' in my timeline with a dozen changes since then by someone else.
I can't sync. When I try to revert and git revert --continue, it says can't commit because I have unmerged files. No idea what that means.
I looked at the files in question and there are no conflict there (the git comment blocks).
Also, these filed specifically have not been modified by anyone else.
How do I just force Github to take the folder from my current local folder and just move on?
I tried deleting the repository folder and recloning, but then it saied it can't clone. Took a while just to get it to clone. But still can't sync!
Thanks!
Try stashing your changes and then syncing/merging.
git stash
git pull
git stash pop
This should merge your local from upstream and have your changes which you can commit.
Note: In some cases, this might lead to a conflict depending on your code, but that should not be a big problem to solve.
Also, unmerged means that you have files that are not committed yet. Do a git status and it should show you.

get previous commit that got deleted on git repository

Yesterday when I was at work, I was working on my project that i have on my home computer. The problem was when I tried cloning the repo it eclipse would crash. So instead I downloaded it manually and initialized the repo and then force pushed to my home computer. This deleted all the history and files in on the repo. I did some googling and tried reverting the commit but it the force push erased the commit history so I can only go back to the force push commit.
I have a computer at home which hasn't pulled the updates since this mistake and I was able to get its commit SHA. I used that on the web and found the last version its still there but I can't pull that commit because it got "deleted" and won't show in the repos history. Is there a way I can use the SHA from the last good commit and make that the master branch restoring my history?
When changing the HEAD (the working position in the git repository), it tracks your history in the reflog. Executing git reflog in the command line will show your complete history. You can read more about it on git-scm.com
When you have the desired commit SHA, you can do a git checkout with it. Executing git checkout [SHA1] will take you to the desired position in the git history. From there, you can make a new branch from it by running git checkout -b "new_branchname".
If you want to set your current branch to the commit, you can run git reset --hard [SHA1]. This would reset the current branch, but the previous state can however be found in the reflog.
I do NOT recommend doing this as general practice BUT...You should be able to force push from the other computer, thus resetting the repo to its former state. Providing you don't want to keep anything you did while making a giant mess of your git repo yesterday.
Since you know the right version you want to recover, it will make things easier.
In your local repo, use below commands:
git reset --hard <commit sha value>
git push -f
Note: if you execute the commands in the local not initialized (not cloned from remote), you should fetch first by git fetch --all, and then execute the two commands .
Now the version will go back to the latest as you need both locally and remotely.

How to recover git repository data if system was crashed during switching branches?

I was switching branch in jboss developer studio (just like eclipse). It asked me to commit your changes before switching. I entered temporary commit as commit message. Then IDE was doing it's work.
But when IDE was doing all this, system was crashed due to unavailability of electricity.
When power was back I saw much of my files were blank, IDE is not recognizing project as git project, git status is saying not a git repository.
How can I recover git repository data if system was crashed during switching branches?
Try to check what's inside the reflog, with :
git reflog
If you are lucky enough you should find the temporary commit into the reflog list, and then you can restore it from there.
In the case you won't find anything inside the reflog try with this command :
git fsck --full --no-reflogs --unreachable --lost-found
The listed commits are copied into .git/lost-found/commit/, and non-commit objects are copied into .git/lost-found/other/ .

GitHub synchronize failure result in rebase - how to get back the committed file

I've made a commit to GitHub but the synchronization was not successful and it abort half way. When I try to get back the files I realized the files in local has been rebased to the previous version that I submitted during the last synchronization.
The new files and editions were lost. May I know whether there's any way to get back the lost data?(now it says "Rebase origin/master **" on my project)
Thank you!
Use the following:
git log
copy any previous commit id.
git reset "commitid".
Now you will have your changes.
Then commit and rebase.