Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
strauss_d_getting_started_with_visual_studio_2022_learning_a.pdf
Скачиваний:
123
Добавлен:
26.06.2023
Размер:
17.04 Mб
Скачать

Chapter 5 Source Control

Figure 5-61.  Select the repo to push

Having the ability to work with multiple repositories in Visual Studio is convenient because I no longer need to open a separate instance of Visual Studio to work on a different repository.

Compare Branches

Visual Studio 2022 now allows you to compare branches. This provides a convenient way to see the differences between the two branches you are comparing and will be helpful before creating a pull request, before merging, or even when choosing to delete a branch.

298

Chapter 5 Source Control

Figure 5-62.  View the branches to compare

As seen in Figure 5-62, when I click the currently checked out branch (NewFeatures), I can see that I also have a branch called master. To compare the NewFeatures branch with the master branch, right-click the master branch and select Compare with Current Branch from the context menu as seen in Figure 5-63.

Figure 5-63.  Compare to master branch

299

Chapter 5 Source Control

Visual Studio will then display a diff between the two branches you selected to compare as seen in Figure 5-64.

Figure 5-64.  The branch diff

I am now able to see exactly what is different between the two branches without leaving Visual Studio.

Figure 5-65.  Changing the preferred diff layout

I can also use the diff configuration options gear in the top-right corner to switch to an inline diff view as seen in Figure 5-65.

Check Out Commit

Visual Studio allows you to check out a specific commit. This can be beneficial because it allows you to go back in time to a previous point in your repo’s history if you need to test a specific section of code. You can also do this for a remote branch, and it saves you

300

Chapter 5 Source Control

from having to create a local branch if you are not planning on adding any new code to it. To do this, open the Git Repository window by selecting the View menu and clicking Git Repository as seen in Figure 5-66.

Figure 5-66.  View the Git Repository

You can also hold down Ctrl+O, Ctrl+R to open the Git Repository which can be seen in Figure 5-67.

Figure 5-67.  The Git Repository window

301

Chapter 5 Source Control

To check out a specific commit, right-click the commit in the Git Repository window as seen in Figure 5-68 and select Checkout (--detach) from the context menu.

Figure 5-68.  Check out a commit

Visual Studio now displays a confirmation window (Figure 5-69) to inform you that by checking out this commit, you will be in a detached HEAD state. In other words, your repo’s HEAD will be pointing to a specific commit instead of a branch.

Figure 5-69.  The checkout commit confirmation

302