Visar inlägg med etikett sourcetree. Visa alla inlägg
Visar inlägg med etikett sourcetree. Visa alla inlägg

söndag 25 april 2021

A SourceTree lover sees Visual Studio catching up

Background

This was supposed to be a post about features that I find important for the daily work I do that the git gui SourceTree has and that Visual Studio's git tool lacks. But instead I learned that Visual Studio is catching up with its Visual Studio 2019 16.10 Preview 2.1 release!

File change preview for historic commits

Navigating the commit history and looking at file changes in Visual Studio is a pain, but today I downloaded Visual Studio 2019 16.10 Preview 2.1 and explored the news in its git tool. Looking at changes in historic commits is no longer a pain!

I also learned that Visual Studio can show diffs as inline or side-by-side.


SourceTree shows all branches in history

In SourceTree you see ALL branches by default, which is the way I like it because I get the full latest commit history context immediately. This isn't possible in Visual Studio, you have to select the branch that has the latest commit to be able to see the history for all branches.


If you ever would like to not see all branches in SourceTree, you can easily turn it off by selecting Current Branch in the dropdown, like this.


To show all branches is a feature under review by Microsoft 
https://developercommunity.visualstudio.com/t/how-do-i-view-the-history-of-all-branches-in-git/934801

Merges are shown better in SourceTree

I find the branch history tree to be more clear in SourceTree. Compare these two images that pictures a branch branched off of master, and then the branch is merged back to master.

In SourceTree it looks just like that, a branch going out from master and then coming back to master.


In Visual Studio it looks like a branch has been branched off from master, but then it looks like master has been merged to the branch!? When merging, the merge commit has two parents instead of one. There is a primary parent (the branch merged to) and a secondary parent (the branch merged from) and VS seems to mix them up.


I added a ticket regarding this.

But the image below, taken from this ticket hints about a rewrite of the the commit history tree visualization in VS. No merge is shown, but the tree looks different, and hopefully it will be easier to follow.



SourceTree auto-adds commits message for merge with conflicts

When doing a merge and the merge results in conflicts, a commit message like this the one below is added automatically by SourceTree. Visual Studio adds nothing. 
Merged ‘master’ into 'a_feature_branch'. Conflicts: # Foo.h # Bar.cpp

To be able to see which files that have had conflicts can be of help when you know that a feature has been added in a file, but that feature suddenly is gone or is buggy, because it probably disappeared in a manual merge conflict resolution that went wrong.

This also seems to be a feature under review.

In SourceTree you can pull a branch that isn't currently active

Yes, you can, and I thought it was something that made my branch handling smoother, but when writing this I can't come up with a scenario where it is needed.

söndag 4 juni 2017

"Learn Git Branching", the site that finally made me get a grip on git!

My git journey

Subversion

Sometimes I feel lucky that the first company I worked for as a software developer was using Subversion instead of SourceSafe. As I remember it, Subversion together with the Windows Explorer integrated Subversion client TortoiseSvn, was pretty easy to learn and felt as a great tool. Sure, there were some gotchas, but still, the learning curve felt pretty flat.

When I moved on, from employment to employment, the companies I came to often used SourceSafe. I could cope with that, because I used Subversion on the side. After many years as a Subversion user, I heard about the greatness of git and tried a few times to get a grip on it... but didn't get it. One of the reasons to that was that as a TortoiseSvn user I thought that TortoiseGit would be almost the same experience. The image below is what you meet when trying to get the source code to your computer, lots of checkboxes I didn't have a clue what they did!


I gave up rather fast, but tried again, and gave up, and so on. 

SourceTree

Finally I found the git visual client SourceTree, that was powerful enough to let me do most of the things I needed. Some visual clients was so stripped that it wasn't possible to do anything but the simplest commands. With SourceTree I could finally work with git and began to learn, but the learning curve felt steep, and the fact that I came from Subversion probably made it steeper than if I hadn't had the Subversion thinking. Anyway, now I learned things, but still many things felt really confusing.

Learn Git Branching

One day, I found the site http://learngitbranching.js.org/ Spending some time on that site made a big difference! Suddenly I got a feel for the differences between Subversion and git branches! The two top reasons I find the site so great is that you solve problems using real git commands and that it shows visually what happens with the commits and branches.


Results

Learning git on my own, using SourceTree and the "Learn Git Branching" site, made it possible for me, on my latest employment, to do the migration of the source code from TFVC to git, set up a branching strategy, and to help my collegues get a quick start with git so they didn't have to take the same long journey as me =)

tisdag 30 maj 2017

Revert a merge commit using SourceTree

Update 1 (no need to investigate the parents)

The use case I need this for is when a feature branch has been merged to master, and after that something arises that makes us want to remove that feature from the master branch again. In the text below I describe how to find the parents of a merge commit, but since the checked out branch always will become the parent number one when merging in another branch, the investigation of the parents isn't needed. The only command needed is therefore
git revert the_hash_of_the_commit_to_revert -m 1


Update 2 (commands for the commit message editor)

When the commit message editor opens up, just accept and exit by writing 
:q
Or, if you want to change the commit message, press i, write your message and then
<Esc> :wq <Enter>

Revert a "normal" commit

Normally when you want to undo the changes of a commit that has been pushed, you can do a reverse commit inside SourceTree by doing a right click on the commit and choose "Reverse commit..." like in the image below.


But if the commit you're trying to reverse is a merge commit you'll get the message:

git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=manager-st revert --no-edit 5a1f18d0d344e4ce9f23b02752cf4674c973cdf4
error: Commit 5a1f18d0d344e4ce9f23b02752cf4674c973cdf4 is a merge but no -m option was given.
fatal: revert failed

Completed with errors, see above.

Which means you've got to use the Terminal window.

Revert a merge commit

The case

Suppose we have the state as seen in the image below. Suddenly we realize that the changes made in the demo_branch are wrong and have to be removed from the master branch.



To do this we have to issue the revert command and specify the -m option. The -m option specifies which of the parents that was the mainline that we want the resulting code to be like.

Identify the commit to revert

The commit we want to undo is the commit with id 0c9c102

Find the correct parent

To the right in the button bar in the top of SourceTree window there is a button for opening the Terminal window.


Click on it and you'll see the Terminal window below.


Run the command git log to list the commits. Find the commit we want to revert (when you´ve found your commit, stop the listing with ctrl-z). In the image below we see that commit 0c9c102 is a merge, having two parents with the ids 618383a (parent 1) and b8a9ad7 (parent 2).



In this case we want to use the commit in the master branch as parent, the commit with id 618383a that is. That parent was listed in the log as the first parent, therefore we refer to it as parent 1.


Execute the revert command

To recap, we want to revert the commit 0c9c102 using parent 1 as the index to the -m (mainline) option. Therefore the command to write in the terminal window becomes:

git revert 0c9c102 -m 1



After issuing the command an editor for editing the commit message opens up (see below). To accept the default message and exit the editor, press Esc and then ZZ.


Now a new commit has been added, which reverts the changes introduced by the merge commit.




Done!

Sources

In case you had a hard time following my explanation, maybe the answers in the sources I used can help you.