How can I retrieve the local changed files which I wrongly reset in git - eclipse

Below is the situation which explains what's the matter about git.
I was using the 'develop' branch and already made several changes to the local files such as .sql, .java, .js...
I made a local branch called 'develop_some_future' since my boss wants to confirm my changes before merging main 'develop' repository.
Apparently my local file changes #'develop' branch have applied to 'develop_some_future' branch and I started editing local files again.
For some reason, I tried to pull the files that my co-workers already committed, but it has failed(Probably I couldn't set 'develop_some_future' branch well). So, I changed current branch to 'develop' branch and tried to pull them.
Fortunately it got worked, and then I tried to back to the 'develop_some_future' branch.
A dialog pops up suddenly while changing the branch and asked me that 'your local change for "~~~.sql" would be deleted since it's not committed yet. To avoid this, please commit that file or choose reset.'
Because I thought only '~~~.sql' would be changed to the latest committed state and that was not a problem, I selected 'reset' button, but unfortunately all local changes have gone.
Anyone knows how can I retrieve the date before reset?
I found that both 'git reflog' and 'git reset HEAD{}' commands are useful.
However, git reflog shows only commit, merge, and checkout changes and so I can't find reset status at all.

I'm afraid your files are gone for good, unless you had previously staged the file somehow (add or stash save).
If it had been staged, a blob object was created by Git which is now dangling (git fsck will tell you dangling objects). You can then resurrect the file by writing the blob's content with git cat-file to a new file.
If not, your'e screwed, and you have to do your work again.
It seems the problem arose in the first place, because you thought that unstaged/uncommitted changes belong to the current branch. They do not, and only live in the working directory. They will be carried over when switching branches (unless, of course, the same file was modified in the branch. Git will then refuse to checkout the other branch).

Related

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.

Why my way to update local files with Github is not working?

First I have a master branch in my remote repo on the internet. And I know if I changed my local files, how to update my local changes to the remote repo. Now the problem is, if I don't want my new changes in my local tracked files, how to return back using updating from the remote repo in github?
I have tried the following things:
I use
git checkout origin master
to get to master repo.
I make sure that one tracked file, named main_32.f90 is changed a little bit in the comment line.
Then I use
git pull
it turns out that everything is up to date.
Already up-to-date.
I then checked the main_32.f90, it is not the original one but the changed one in comment line. So it means that the git pull is not working.
So how to do it?
If you don't want to keep your local changes, you can do a hard reset to a pointer, branch, sha1, etc to discard all changes. git reset --hard HEAD.
Use this kind of aliases to have a pretty view of your working tree if you are a console fan and don't want to use any GUI as suggested by other users.

GitHub for Mac Commit & Sync has overwritten local files How can I revert

I used 'Commit & Sync' and for a brief moment the 'Merge Conflics' dialog popped up just like VonC described here. Next all my local files have been overwritten. But there is now record in the history and also not if I run git reflog show
How can I revert this sync and get back my up to date local files?
Any ideas?
Your changes are probably being stashed (git stash). For some reason Github on Mac stashes any local changes so it can pull down changes from the remote repo (even though it misleadingly states that it hasn't done anything because it would overwrite changes).
WARNING: I would make a backup of your directory before trying any of the following in case something goes wrong.
Open a terminal in your repo's directory and type git stash list. You should see an entry like stash#{0}: GitHub: Stashing to pull in remote changes. If you type git stash show stash#{0} it will display a list of files with all of the changes you had before.
To restore those changes, type git stash apply stash#{0} and it will write those changes to your directory (possibly overwriting changes you pulled from your remote repo). You can also use git stash pop #stash{0} to retrieve the code and delete the stash immediately after, but I'd hold on to it until you're sure you don't need it.
I've found the original files in the Stashes and restored them

Github pull request loaded with empty file changes

Ok, I've got a problem that I have no idea how to go about solving.
First, a bit of history:
I pulled from my upstream to bring in changes and merged them with the branch I was working in. At the time, I may have been using a console window with root access. I say this because I noticed a day later I couldn't save to a lot of the files in my local repo. I noticed the owner / group had been changed to root and permissions were 644. After going through and hunting down all of the screwed up files, I then pushed some changes I had made back to my remote working branch.
A week later (now), and I've added several other commits to an open pull request from my remote branch. In the middle of them was the commit I made after fixing my local repo file permissions. I noticed it has some 1200 "empty" files (no changes). I'm a little concerned that merging this pull request upstream could cause big problems and I have no idea how to remove this one commit or if it's even possible...
I tried creating a new branch and using cherry-pick to get all but the one commit, but I've removed files and couldn't merge the older commits that saw a "conflict" between the file that existed at the time and one that no longer exists in the local repo...
Anyway, any thoughts?
The solution I used was to reset my local branch to the commit just before the one that I didn't want. I then copied and pasted the commits after the failed commit into code, recommited, and pushed toa new branch. Long way around, yes. But it wasn't bad as I didn't have a lot of code to fix. A simpler method might have been to use cherry-pick to pull the later commits into my reset local branch, but I tried that at one point and had problems...

EGit Commit to Remote Branch without Local Branch

I had a branch I was working on for a long time on my desktop. First I commit changes to my desktop's local branch, then push them to the remote branch and everything is dandy.
This morning, I was working on my laptop and selected the remote branch to change. The image below shows what my EGit repository window looked like on my laptop, except there was no local "MethodMigration" branch (there was a local master though). The remote "MethodMigration" branch had the little black check-mark next to it telling me that I'm viewing it as shown in the picture.
https://docs.google.com/file/d/0B7yGmb99B5enZm5OcTcydnEwLUE/edit (Sorry for the ghetto google drive link. I couldn't figure out how to get an image link)
Anyhow, I started adding a whole bunch of stuff. After I was done, I did a "Team->Commit->Commit & Push" after giving it a message. At that point, I remembered that I hadn't made a local branch for it yet... It told me "Nothing to push" even though a whole bunch of stuff had just been specified (which kind of makes sense since I never cloned the remote branch to make a local copy in the first place). The bad part is that all of my code was reverted back to the original "MethodMigration" remote branch code. Additionally, BitBucket shows no commits or anything.
Where did all my changed code go? Is there a way to get it back?
No worries!
You can use git reflog to find the commit id SHA of the lost commit. After that simply merge it with your local branch:
git merge <commit-id>