Corrado's Blog 2.0

Online thoughts of a technology funatic

Learning Git with Visual Studio #2

In the previous post we learned how to connect a solution to Git source control, we’ll now pay attention to the status of each file inside the solution.
Git defines several status for the files it tracks, they can be:

-Untracked
Git knows nothing about that file, it totally ignores it
-Tracked
Git knows about that files and keep the history of it
-Modified
Git knows that that file has been modified compared to tracked version
-Committed
The file in the solution matches the one in the source control

Note: This is my personal definition, git uses a different terminology, but you got the point.

Take a look at following picture

image

In this case the .pfx file is untracked (ignored) because of the .gitignore file exclusion, if we want to include it we can right click it and select Add Ignored file to Source Control…

image

Turning it into a Tracked (or staged) file (equivalent to Git Add command)

image

Both Class1 and .pfx file are now tracked, meaning that git knows about that but it hasn’t started recoding changes because we have not commited them yet.
To Commit them we can go to  Team Explorer inside Visual Studio and select Changes where we will see something like this

image

Where we see two different sets of files ready to be Committed, let’s add the mandatory comment and then we will be able to commit staged changes

image

Stages changes are a way to control what files are part of a specific commit, and are an alternative to a “general” commit where we commit everything that has changed.
After clicking Commit Staged here’s what we see

image

And if we select View History under Action buttons we’ll see this

image

Ok, let’s now add another class (Class2) to our project, let go to Team Explorer window and let’s add a commit comment, we’ll se that button has a Commit all text where we can commit everything that has changed in one shot.

image

Ok, but what if i want to split committing of Class1 to commit of Class2 for better separation? Just right click the Class1 file and select Stage, add a comment and click Commit Stages, only Class1 addition will be tracked into history.

image

History

image

But what if i changed my mind and want to correct my last commit, maybe including Class2 as well? Just stage Class2 and use Amend Last Commit option under Actions (don’t use Commit staged that will generates a new commit entry)

image

and the previous commit will be updated with both Class1 and Class2 changes.

image

Most of the times I don’t do such granular commits, but since you can revert to a specific commit entry having using this option can help you track precisely the evolution of your app.

No Responses to “Learning Git with Visual Studio #2”

RSS feed for comments on this post. TrackBack URL

Leave a Response