PowerShell에서 헤더에 Git 정보에서 자동으로 생성 날짜와 변경 날짜와 시간을 삽입해 보았습니다.
9676 단어 VisualStudioPowerShellGit
동기
대량의 .h 및 .cpp 파일에 다음과 같은 헤더를 삽입해야 합니다.

140 파일 가까이 있는 소스 코드의 헤더에 수작업으로 날짜를 넣는 것은 무리라고 생각했다.
헤더를 넣는 방법?
이번에는 헤더를 모든 소스 파일에 삽입하기 위해 Visual Studio 확장 기능 License Header Manager을 사용했습니다.
다음 템플릿 파일을 만들었습니다. 나중에 대체하기 위해 장소 홀더 ${created_date}
와 ${modified_date}
를 만들었습니다.
(또한 ${ydeagames}
는 나중에 이름으로 바꿀 예정이다.)
3DShootingGame.licenseheaderextensions: designer.cs generated.cs
extensions: .cs .cpp .h
// Copyright (c) 2019-2020 ydeagames
// Released under the MIT license
// https://github.com/ydeagames/3DShootingGame/blob/master/LICENSE
//
// Author: ${ydeagames}
// Created: ${created_date}
// Modified: ${modified_date}
프로젝트를 마우스 오른쪽 버튼으로 클릭하고 License Headers > Add License Headers to All Files
를 선택하여 모든 파일에 헤더를 삽입 할 수 있습니다.

자리 표시자를 날짜로 바꾸기
이번에 대체하기 위해 비교적 간단한 PowerShell을 채용했다.
Git에서 파일을 만든 날짜는
git log --diff-filter=A --follow --pretty="format:%ci" -1 -- $file.Path
최종 변경일은
git log -1 --pretty="format:%ci" $file.Path
에서 얻을 수 있다.
솔루션이 있는 폴더에 PowerShell 배치 파일인 .ps1
파일을 만들었습니다.
작성 날짜 및 시간 대체
ReplaceCreationDate.ps1$sel = '\${' + 'created_date' + '}' # 置き換える対象
# 対象を含むファイルをループ
foreach ($file in Get-ChildItem . * -Recurse -Force | Select-String $sel -casesensitive)
{
Write-Host "Processing " -ForegroundColor Red -NoNewline
Write-Host $file.Path
# Gitの作成日時を取得
$gitCreated = git log --diff-filter=A --follow --pretty="format:%ci" -1 -- $file.Path
Write-Host 'Created: ' + $gitCreated
((Get-Content -path $file.Path -Raw) -replace $sel,$gitCreated) | Set-Content -Path $file.Path
}
변경 날짜 및 시간 대체
ReplaceModifiedDate.ps1$sel = '\${' + 'modified_date' + '}' # 置き換える対象
# 対象を含むファイルをループ
foreach ($file in Get-ChildItem . * -Recurse -Force | Select-String $sel -casesensitive)
{
Write-Host "Processing " -ForegroundColor Red -NoNewline
Write-Host $file.Path
# Gitの変更日時を取得
$gitModified = git log -1 --pretty="format:%ci" $file.Path
Write-Host 'Modified: ' + $gitModified
((Get-Content -path $file.Path -Raw) -replace $sel,$gitModified) | Set-Content -Path $file.Path
}
자리표시자를 날짜로 대체할 수 있습니다. 죄송합니다.
Reference
이 문제에 관하여(PowerShell에서 헤더에 Git 정보에서 자동으로 생성 날짜와 변경 날짜와 시간을 삽입해 보았습니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/ydeagames/items/4ddc5a4ae7b7de6a0847
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
extensions: designer.cs generated.cs
extensions: .cs .cpp .h
// Copyright (c) 2019-2020 ydeagames
// Released under the MIT license
// https://github.com/ydeagames/3DShootingGame/blob/master/LICENSE
//
// Author: ${ydeagames}
// Created: ${created_date}
// Modified: ${modified_date}
git log --diff-filter=A --follow --pretty="format:%ci" -1 -- $file.Path
git log -1 --pretty="format:%ci" $file.Path
$sel = '\${' + 'created_date' + '}' # 置き換える対象
# 対象を含むファイルをループ
foreach ($file in Get-ChildItem . * -Recurse -Force | Select-String $sel -casesensitive)
{
Write-Host "Processing " -ForegroundColor Red -NoNewline
Write-Host $file.Path
# Gitの作成日時を取得
$gitCreated = git log --diff-filter=A --follow --pretty="format:%ci" -1 -- $file.Path
Write-Host 'Created: ' + $gitCreated
((Get-Content -path $file.Path -Raw) -replace $sel,$gitCreated) | Set-Content -Path $file.Path
}
$sel = '\${' + 'modified_date' + '}' # 置き換える対象
# 対象を含むファイルをループ
foreach ($file in Get-ChildItem . * -Recurse -Force | Select-String $sel -casesensitive)
{
Write-Host "Processing " -ForegroundColor Red -NoNewline
Write-Host $file.Path
# Gitの変更日時を取得
$gitModified = git log -1 --pretty="format:%ci" $file.Path
Write-Host 'Modified: ' + $gitModified
((Get-Content -path $file.Path -Raw) -replace $sel,$gitModified) | Set-Content -Path $file.Path
}
Reference
이 문제에 관하여(PowerShell에서 헤더에 Git 정보에서 자동으로 생성 날짜와 변경 날짜와 시간을 삽입해 보았습니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/ydeagames/items/4ddc5a4ae7b7de6a0847텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)