연습 - 리포지토리에 파일 커밋 및 파일 기록 보기

완료됨

이전 연습에서는 장난감 회사 웹 사이트의 Git 리포지토리를 초기화했습니다. Bicep 파일을 추가했지만 커밋하지는 않았습니다.

이 연습에서는 다음을 수행합니다.

  • 이전 연습에서 만든 파일을 커밋합니다.
  • 새 Bicep 모듈을 추가하고, Git을 사용하여 Bicep 코드의 차이점을 비교합니다.
  • 업데이트된 Bicep 코드를 커밋합니다.
  • 커밋 기록 및 기본 Bicep 파일의 기록을 봅니다.

Bicep 코드를 더 많이 변경하는 프로세스는 Git 및 Visual Studio Code가 변경 내용을 추적하고 관리하는 데 어떤 도움을 주는지 보여줍니다.

Git CLI를 사용하여 Bicep 파일 커밋

  1. Visual Studio Code 터미널에서 다음 명령을 실행하여 main.bicep 파일을 스테이징합니다.

    git add deploy/main.bicep
    
  2. 다음 명령을 실행하여 스테이징된 변경 내용을 커밋하고 커밋 메시지를 입력합니다.

    git commit --message "Add first version of Bicep template"
    

Bicep 모듈 추가

여기서는 Bicep 모듈을 추가하고 main.bicep 파일에서 이 모듈을 참조합니다.

  1. deploy 폴더에 modules라는 하위 폴더를 만듭니다.

  2. modules 폴더에 app-service.bicep이라는 새 파일을 만듭니다.

  3. app-service.bicep 파일을 열고 저장합니다. 그러면 Visual Studio Code에서 Bicep 도구가 로드됩니다.

  4. 다음 코드를 app-service.bicep 파일에 복사합니다.

    @description('The Azure region into which the resources should be deployed.')
    param location string
    
    @description('The type of environment. This must be nonprod or prod.')
    @allowed([
      'nonprod'
      'prod'
    ])
    param environmentType string
    
    @description('The name of the App Service app. This name must be globally unique.')
    param appServiceAppName string
    
    var appServicePlanName = 'toy-website-plan'
    var appServicePlanSkuName = (environmentType == 'prod') ? 'P2v3' : 'F1'
    var appServicePlanTierName = (environmentType == 'prod') ? 'PremiumV3' : 'Free'
    
    resource appServicePlan 'Microsoft.Web/serverFarms@2022-03-01' = {
      name: appServicePlanName
      location: location
      sku: {
        name: appServicePlanSkuName
        tier: appServicePlanTierName
      }
    }
    
    resource appServiceApp 'Microsoft.Web/sites@2022-03-01' = {
      name: appServiceAppName
      location: location
      properties: {
        serverFarmId: appServicePlan.id
        httpsOnly: true
      }
    }
    
  5. app-service.bicep 파일을 저장하고 닫습니다.

  6. main.bicep 파일을 엽니다.

  7. 매개 변수 선언 아래에 다음 매개 변수 선언 및 모듈 정의를 추가합니다.

    @description('The name of the App Service app. This name must be globally unique.')
    param appServiceAppName string = 'toyweb-${uniqueString(resourceGroup().id)}'
    
    module appService 'modules/app-service.bicep' = {
      name: 'app-service'
      params: {
        location: location
        environmentType: environmentType
        appServiceAppName: appServiceAppName
      }
    }
    
  8. main.bicep 파일을 저장하고 닫습니다.

차이점 비교

main.bicep 파일을 변경했으므로 차이점을 살펴보겠습니다. 스테이징 및 커밋하려는 각 파일의 차이점을 검토하는 것이 좋습니다. 검토를 수행하여 변경 내용이 올바른지 확인합니다.

  1. Visual Studio Code에서 보기>소스 제어를 선택하거나 키보드에서 Ctrl+Shift+G를 선택합니다.

  2. 열리는 소스 제어 패널에서 main.bicep 파일을 선택합니다.

    파일 차이점 보기가 열립니다.

    Screenshot of Visual Studio Code that shows the differences between the current main.bicep file and the modified version.

    Visual Studio Code에 변경 내용이 표시됩니다. 왼쪽은 원래 파일이고, 오른쪽은 변경된 파일입니다. 파일에 추가된 내용은 녹색으로 표시됩니다. 파일을 편집하여 콘텐츠를 제거한 경우에는 삭제된 부분이 빨간색으로 표시됩니다.

  3. app-service.bicep 파일의 차이점을 엽니다.

    이 파일은 새 파일이며 아직 리포지토리에 추가되지 않았기 때문에 차이점 보기의 왼쪽에 아무것도 없습니다.

Visual Studio Code를 사용하여 업데이트된 Bicep 코드 커밋

변경 내용을 검토하고 이상 없는 것으로 확인되었으므로, 파일 업데이트를 커밋합니다. 이번에는 Visual Studio Code를 사용합니다.

  1. 소스 제어를 엽니다.

    변경된 파일 2개가 표시됩니다. 파일이 보이지 않으면 Visual Studio Code가 변경 내용을 검색할 수 있도록 새로 고침 단추를 선택합니다.

    Screenshot of Visual Studio Code that shows Source Control, with the Refresh toolbar icon highlighted.

  2. 변경된 두 파일을 각각 선택하여 스테이징합니다. 각 파일에서 더하기(+) 아이콘을 선택하거나, 각 파일을 길게 누르고(또는 마우스 오른쪽 단추로 클릭) 변경 내용 스테이징을 선택하면 됩니다.

    Screenshot of Visual Studio Code that shows Source Control, with the main.bicep context menu displayed and the Stage Changes menu item highlighted.

  3. 원본 제어의 맨 위에서 다음과 같이 구체적인 커밋 메시지를 입력합니다.

    Add App Service module
    
  4. 커밋 메시지 텍스트 상자 위에 있는 확인 표시 아이콘을 선택합니다. 또는 커밋을 선택할 수 있습니다.

    Screenshot of Visual Studio Code that shows Source Control, with the commit icon highlighted.

    Visual Studio Code가 두 변경 내용을 커밋합니다.

Git CLI를 사용하여 커밋 기록 보기

  1. Visual Studio Code 터미널에서 다음 명령을 입력하여 리포지토리의 커밋 기록을 봅니다.

    git log --pretty=oneline
    

    출력은 다음 예제와 유사합니다.

    238b0867f533e14bcaabbade31b9d9e1bda6123b (HEAD -> main) Add App Service module
    9e41f816bf0f5c590cee88590aacc977f1361124 Add first version of Bicep template
    
  2. 출력을 검사합니다. 두 커밋이 커밋 기록에 표시됩니다.

Visual Studio Code를 사용하여 파일 기록 보기

단일 파일의 기록, 해당 커밋에서 파일의 상태, 커밋이 적용된 변경 내용도 볼 수 있습니다.

  1. Visual Studio Code에서 탐색기를 엽니다.

  2. main.bicep 파일을 선택하고 길게 누른(또는 마우스 오른쪽 단추로 클릭) 다음, 타임라인 열기를 선택합니다.

    Screenshot of Visual Studio Code that shows the Explorer panel, with the shortcut menu displayed for the main.bicep file and the Timeline menu item highlighted.

    타임라인이 열리고 두 커밋이 모두 표시됩니다.

    Screenshot of Visual Studio Code that shows the timeline for the main.bicep file, with two commits listed.

  3. 목록에서 각 커밋을 선택하여 해당 시점의 파일 상태를 확인합니다.