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

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.

Related

Delete Commit on Github through Browser

This is my first time using github and I was having trouble with some of the commands and committed the same thing about 7 times through terminal. I don't know how this is possible because I thought you could only commit if there are changes made in the file. I wasn't seeing anything every time I committed so I kept deleting and remaking the same repository with the same name and tried committing over and over until I finally saw them now but theres too many I just want to see 1 initial commit not all 7. I want to know if there is a way to delete a commit if I have my github account open in my browser not by using terminal.
Note on possible duplicate: Please do not mark question as duplicate. I know there are similar questions/exact same questions asked. However I have read those and most of them are commands you have to type in the terminal and because there is no way to undo that I would prefer to do this through the website. I don't want to accidentally delete something I want and not be able to get my work back later. If there is something else I can use rather then terminal I would prefer to use that instead.
If you push your commits then I'm afraid there's no way to delete them. But if you haven't pushed your commits to the remote repository, then you can change the HEAD to the previous commit.
If you had pushed your commits in a branch, and then delete the branch without merging it with any other branches (you can not delete the default and protected branches), then technically the commits will also be deleted.

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

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

Beginner help: How to remove commits to the master branch from history while keeping the changes made?

I'm new to github and have been working on a group project for school. Recently it turned out we were missing some stuff and nothing was organized (every file was just uploaded into the main directory) so I removed everything using a command in the github shell. Then I proceeded to make files and organize all the code and re-upload and store everything in there.
However, when I did this, I had to keep committing every time I made a new folder and stored a bunch of files in it. I would like to keep the changes made during those commits (because I created folders and re-uploaded the stuff), but I want to remove those commits from the history because they are cluttering up the project.
Is this possible, and if so can you please walk me through the steps. Also I'm new to github so I don't know much.
Here is a picture of the ones I want to remove from my history because they are cluttering up the screen (see red marks):
Thanks :)
EDIT: PLEASE NOTE: I don't want to revert the changes, I just want all those history to be removed because they are cluttering up the commit history.
You should use:
git rebase -i HEAD~14
To rebase and squash your unwanted commits. Just use p to mark the last commit and use f to mark the unwanted commits for squashing it with the previous commits. This will remove it from commit log keeping the changes.
More info: https://git-scm.com/book/gr/v2/%CE%94%CE%B9%CE%B1%CE%BA%CE%BB%CE%B1%CE%B4%CF%8E%CF%83%CE%B5%CE%B9%CF%82-%CF%83%CF%84%CE%BF-Git-Rebasing

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.

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.