Late yesterday I finished up a day's worth of work and went to github and commited, then hit the sync button. I briefly saw a message on the screen saying something about needing to fix merge conflicts, but the message was self-dismissed before I could read it completely.
My outstanding commit disappeared, so I figured all was well. This morning I started work again and ALL the new code that I did had been reverted to the prior commit from two days before. There is no mention of any of the changes I had made nor of the commit I did just before finishing up my work day... they are just gone.
Any suggestions on recovery?
UPDATE
For what it's worth, I was browsing the log files in my git folder and I see my commit:
37c661799950211c713630301cf8cbe609de6c59 f94366329fa93cec529b83b34a607449725f5270 [user info removed] 1360710557 -0700 commit: Shout page
f94366329fa93cec529b83b34a607449725f5270 b588ed19e77ef55611a4a82896c5ef2c26f3e4cd [user info removed] 1360710567 -0700 checkout: moving from master to b588ed19e77ef55611a4a82896c5ef2c26f3e4cd^0
b588ed19e77ef55611a4a82896c5ef2c26f3e4cd b588ed19e77ef55611a4a82896c5ef2c26f3e4cd [user info removed] 1360710576 -0700 rebase finished: returning to refs/heads/master
Try to use git reflog to find the hash of the lost commit. You can then either use git cherry-pick, git merge or git reset --hard (depending on what it is you want to do with the lost history) to recover. If you need to see diffs in order to identify your commit, use git reflog -p.
You probably did a local commit first, don't you? Check your local branch first:
git log --oneline
Not sure what you did, but if there was a merge conflict while pushing, you should still have your changes locally.
Related
I am new to github commands and I am a bit confused about what I am doing.
I want to delete the "MegaMan Game" commit, revert all changes, and make it dissapear from github
history. Following this other stack overflow question Delete commits from a branch in Git, I ran the git reset --hard HEAD ~1 command. The commit seems to be deleted judging by the git log command, but on the github website it still shows that the "MegaMan Game" commit is still there. Also in source tree happens the same thing. The commit still shows there.
I am a bit confused. Is the website wrong about the commits? Did I run the command wrong?
Here is an image with the exact commands and what git
This is a noob question. I need help to undestand how this works.
You deleted commit in your local branch. You must send this change to the upstream branch(to github).
git push --force
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.
There was some github.com down time today that I wasn't aware of until I went to push about one dozen local commits.
https://status.github.com/messages
https://twitter.com/githubstatus
Here's the message I received when trying to push to github.com:
remote: Unexpected system error after push was received.
remote: These changes may not be reflected on github.com!
remote: Your unique error code: abcdefghijklmnopqrstuvwxuz
Now that github.com is back up, when I view the project commit history online, I can see these dozen commits have not been pushed up to the repo.
I figured I could just push these changes again with git push origin master, but I am told Everything up-to-date. Similarily a git pull origin master also shows Everything up-to-date.
How can I get these local changes pushed up to my repo on github.com?
I hate to answer my own question so quickly, but with a little tinkering, here's a quick work around I discovered:
echo "bar" >> foo.txt
git add foo.txt
git commit -m "Add foo.txt"
git push origin master
git rm foo.txt
git commit -m "Remove foo.txt"
git push origin master
This properly refreshed the commit history for my github.com repo. This should be safe to do, but definitely take a backup of your local code before trying it.
I agree with Yen Chi, he should have made this an answer. At the least, do an empty commit:
git commit --allow-empty
Pushing another commit for me didn't work.
Instead, creating a dummy branch, from the web interface, solved the problem.
I just had this too, and yes, pushing another commit fixed the problem.
I think that the source of the problem may be that I was pulling from the same repo at the same time (I use submodules). That pull yielded everything up to date, while the first push was still hanging (and then eventually spitting out that error message).
git commit --amend
git push -f origin HEAD
or if you don't like that
git commit --allow-empty
git push origin HEAD
So I have a commit to my local branch that has yet to be pushed to my remote. I worked a little after my local commit and decided to go back to what I had committed. I selected the Discard All Changes . . . under Source Control but it seemed to go back farther then I wanted. I can see the commits under my History . . . but when I select Pull . . . all I get is options for my remote branch (which still shows a branch that I terminated, so helping me refresh that would be great too but the other thing is more important right now).
Any and all suggestions are greatly appreciated.
Solution: So what I ended up doing was using git log to find the commit that I wanted. I copied the commit number. Then git reset --hard *commit #*. The files were in my Finder window but no in my Xcode project, so I went to Files->Add Files to "projectName" and added the files. After I assured myself that everything was fixed I committed my build using git push --force.
Hope that is helpful to someone, feel free to comment if you have any questions on my solution.
CGTheLedgend,
So when you git pull you are actually pulling source code from your remote repository into your local one. Instead what you want to do is a git log which will show all your commits in the following format:
commit f5c5cac0033439c17ebf905d4391dc0705dbd5f1
Author: CGTheLegened
Date: Fri Sep 6 14:36:59 2010 -0500
Added and modified the files.
commit c14809fafb08b9e96ff2879999ba8c807d10fb07
Author: CGTheLegened
Date: Tue Sep 4 08:59:32 2010 -0500
Just simple test for core.editor.
... etc ...
From here, you want to use the git reset command to go to a specific commit. If you do:
git reset --hard c14809fa
To make your local code and local history be just like it was at that commit.
Please let me know if you have any questions!
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.