Clicked reset branch to current commit and lost all my work, what the heck have I done? - atlassian-sourcetree

I am brand new to Source Tree and have no idea what Im doing but I hope I didn't just lose my work.
I clicked a button that says reset branch to current commit, and chose the "Mixed" Option. I then pushed my files. But after going back into UE4 (a program Im tracking) I noticed that my files have gone back a really long time. I can see all the files I have in the "Working Copy" section of source tree, but all of them say "Missing" and am too afraid of doing anything in fear of losing it all. I need help on what button to press to undo my changes (CTRL Z DOESNT WORK :( )
Here are some pictures of where I am.
If it says "Working Copy" and I am able to click "Open Before" I assume the files still exist, I hope.
If I can, how do I get my Files back to the way they were before I messed up.

If you committed the changes before using the reset branch, the changes are not lost.
I'll explain this using command line commands, but I guess there are advanced GUIs that can achieve the same thing.
Open a command line interface of your choosing that has access to git commands, then navigate to the project folder
$ cd /path/to/project/root
Next, check the git reflog
$ git reflog
874333c HEAD#{0}: reset: moving to 874333c
5dc3401 HEAD#{1}: commit: committed something awesome
4ef6395 HEAD#{2}: commit: fixed bug related to ballistics computation
d5cb3b3 HEAD#{3}: commit: added ballistics computation
What you want to do now is to reset your branch again, but this time to the state it was in before (ie. 5dc3401) you did a reset to the current state it's in
$ git reset 5dc3401

Related

Reverting one file in GitKraken

It is possible in GitKraken to revert changes of a single file to an earlier commit instead of reverting an entire commit?
Answer
A revert in the git-sense of it can only be performed on a commit. It introduces a new commit that exactly negates the reverted commits' changes. See here. GitKraken supports this: right click on a commit, Revert <branch> to this commit.
What you want to accomplish, however, can be done via git checkout. I do not think GitKraken supports this funtionality for a single file yet. You can, however, use the command line.
Reset single file via command line
git checkout <commit> <file>
Check out a previous version of a file. This turns the <file> that
resides in the working directory into an exact copy of the one from
<commit> and adds it to the staging area.
Documentation can be found here.
git checkout HEAD~1 <filename> will thus reset a single file to the commit before the current HEAD.
You can accomplish this in the GitKraken UI, but it's a little roundabout:
Revert the most recent commit(s) back to where the file was deleted, but when GitKraken asks if you want to immediately commit the reversion, click no.
Unstage all changes
Stage only the add for the file you're trying to restore
Right click in Unstaged, and Discard all
This should leave you with only an add for the one file you wanted to restore. Commit that, and now you've got your one file back.
Note that this can work across numerous commits, not just one... but since it's going to have to roll back everything from all of those commits, and then discard all of the rollbacks (except one) it can be quite slow if involves massive changes. In situations like this, it is probably better to use the git CI as suggested in kowsky's answer.
Although it doesn't strictly involves using git commands, GitKraken offers the possibility to visualize the content of any project file at any given commit.
When acting on a single file, it might be much easier to copy/paste the targeted commit file's content than using complicated git commands that might very well end up messing your whole project's commit history.
To achieve this, simply:
Open your git project in GitKraken
Click on the desired commit in the commit history line
In the right panel, check the View all files checkbox
Locate the desired project file and click on it
The file content will be displayed in the main panel
You can now copy/paste the content
Simple and efficient when you only need to revert a very limited number of files...
GitKraken 7.3.0 (probably older versions too) does allow for effectively running git checkout on a single file in the UI: Right click on the file under "unstaged files" and select "discard changes". Works on folders as well.
(This answer was previously a comment to the accepted answer)
You can make an UNDO to the last commit edit it and after that make a Force push to overwrite that. Works very well
Hope GitKraken can do this, as "TortoiseGit" does.

How can I view the history of a branch that isn't checked out?

How can I view the history of a branch or a commit, that isn't the one I've currently got checked out?
If I'm on master, and I want to see the log of a sidebranch, or a commit, or a tag, then in the command line this is very easy:
git log $BRANCH_NAME
git log $COMMIT_HASH
git log $TAG
...but I'm not finding any way to do that in SourceTree.
The best I've found is:
Check out the thing whose log I want to see. This obviously touches a whole bunch of files unnecessarily.
If the log view is displaying all branches, I can jump to a branch or a commit in the log view -- but, I'll have all branches in the log view; I can't see just the branch/history that interests me.
Am I missing something? I'm having a hard time understanding how you can even use git effectively without being able to navigate your history and zoom in on things.

Numbers on the push and pull button of SourceTree won't change

I started using SourceTree few days ago and after I committed and pushed my changes to the remote GitHub repository, the numbers on the buttons remain the same, for example if the number on the push button becomes 3 when I committed a change, after I pushed it; it needs to be 0 or empty. But that's not the case here, it remains the same even though it has successfully been pushed. I also checked that my changes had been pushed using a web browser by going to the GitHub site. Is it because of the branch that I have pulled from and am pushing to are different or something else? Can any one please help cause I don't understand it... Thanks!
The numbers shown on the right hand side of the Branches panel reflect how many commits ahead or behind the Tracking Branch you currently are. If the numbers aren't what you expect, you should verify that the branch is tracking what you actually want.
You can verify the tracking branch by right clicking your local branch (as depicted below) and expanding the Track remote branch menu item. Finally, if you want to change the tracking branch simply click the new target from the list and Sourcetree will update accordingly. Hopefully that helps make sense of the disconnect that can happen when you rename branches and provides some details around why it happens and a simple way to resolve.
The same thing also happened to me too, I was working on branch I had push everting but was keeping appearing one unsend Push and miraculously also appear unsend Push on Master.
So what did was the same as Hristo Staykov and Sammie remove the Master branch from my local computer, since I had one miraculously unsend Push on Master did need to run this line terminal to remove the branch:
git branch -D master
And then Repository > Refresh Remote Status
I simply use the keyboard shortcut from the Repository menu:
CTRL+ALT+R (or control+option+R if you prefer)
My guess is that the shortcut would be the same or at least similar on Windows. Just look for the option called Refresh Remote Status under the Repository menu.

Difficulty in switching between various versions of code and commiting changes using SVN in MATLAB

I am using SVN for version control in MATLAB 2014b. I have edited my file 'main.m' three times and commited changes to SVN repository. Thus there are three versions of my file, say commmit1, commmit2 and commmit3. Now, I wanted to revert my file from commit3 to commit2, make some changes in commit2 and finally commit this edited version to create commit4. I have successfully reverted from commit3 to commit2 and made some changes in it. But, now I am unable to commit changes made to commit2. It shows error commit failed,'main.m' is out of date. Please help me in sorting out the issue.
If you are using TortoiseSVN as client the follow this procedure.
Select the file and right click and then click on TortoiseSVN
Proess the show log option from drop down menu andyou will see a window
select the specific checkin which you want to revert to.
Press right click and then press "Revert to this revision"

How to discard latest github push made with Xcode

I have been using Xcode with GitHub. I committed some bad data and I want to revert the merger. How might I do that? Or is there no way of doing it through Xcode? I am using Xcode5.
Xcode does not allow you to do this, but Github for Mac does a good job at bringing back a previous commit: https://mac.github.com
Add your repository to GitHub for Mac, then click the History tab. From the list on the left, pick the commit you'd like to bring back. You'll see what's changed in the window on the right (a diff across multiple files).
To bring back your previous commit, click the little gear icon above the diff window and you'll have two choices: "revert" and "roll back".
From what I understand "revert" undoes only the changes of said commit, whereas "roll back" will change the entire code to the state as it was in this commit. If you only go back a single commit there's no difference, but when you go back several commits then "roll back" is like going back in history, while "revert" leaves the other commits intact.