はつねの日記

Kinect, Windows 10 UWP, Windows Azure, IoT, 電子工作

BFG Repo-CleanerをWindowsで使って、gitリポジトリからファイルを削除する

Gitリポジトリから不要なファイルを削除したいような場合、直前ならばまだしも過去のコミットから削除しようとすると大変です。
そんな時に便利なのが「BFG Repo-Cleaner」です。
github.com

検索すればネット上にいろいろ情報はありますが、「あれ?Windowsのときはどうするんだ?」と検索結果を読みながら若干手探りなところがあったので、忘備録として記載しておきます。

前提

  • Visual Studio 2022を使っていて、OpenJDKもインストール済

  • SourceTreeと使っている(Git for Windowsなどでもよい)

背景

リモート側を別の場所に移行する必要に迫られてローカルリポジトリをpushしようとしたところ、過去のコミットで大きなファイル(その後はそのファイルはいらなくなったので削除もコミットされている)があるということでpushが失敗してしまいました。
Git LFSが使うという方法もあるのですが、いらないファイルなので該当ファイルを削除してからPushする方法をとりたい。

悩んだポイント

Windowsではbfgの実行はどこですればいいのか?

手順

事前準備

事前にGitリポジトリをcloneしておくと万が一失敗したときにリカバリーできるそうです。

bfgのダウンロード

GitHubのBFG-Windowsリポジトリのリリースページからbgfのjarファイルをダウンロードします。
2022/05/09時点では1.13.0が最新です。
Release BFG-1.13.0 (2020-01-08) · wjk/BFG-Windows · GitHub

Open in Terminal

Visual Studioで該当ソリューションを右クリックして「Open in Terminal」を開きます。

これでソリューションのルートフォルダで「開発者用PowerShell」が起動できます。

java -jar c:\Users\hatsune\Downloads\bfg-1.14.0.jar --delete-files hogehoge.a .git

と入力すれば、ソリューションフォルダ直下の「.git」フォルダの内容を参照してリポジトリから「hogehoge.a」ファイルを削除してくれます。
正常に動作した場合は最後に次のように表示されます。

BFG run is complete! When ready, run: git reflog expire --expire=now --all && git gc --prune=now --aggressive

2つのgitコマンド、git reflog expireと git gcを実行するように即されていますね。

後処理

次に、ここがキモなのですが、「開発者用PowerShell」からいったん離れて「Git for Windows」や「SourceTree」などのコマンドプロンプトを開いて次のコマンドを実行します。

$ git reflog expire --expire=now --all && git gc --prune=now --aggressive
Enumerating objects: 24347, done.
Counting objects: 100% (24347/24347), done.
Delta compression using up to 4 threads
Compressing objects: 100% (23104/23104), done.
Writing objects: 100% (24347/24347), done.
Total 24347 (delta 18601), reused 4215 (delta 0), pack-reused 0
Removing duplicate objects: 100% (256/256), done.

リモートにpush

これであとはリモートにpushします。

$ git push -u origin master

リモートとローカルのリポジトリの整合性がとれないので怒られると思うので「-f」で強制プッシュします。

$ git push -f

まとめ

パスをきちんと設定しておけばよいのかもしれないけれど、「開発者用PowerShell」と「Gitツールのターミナル」の二刀流でサクッとやってしまうのもいいのかなと思いました。

転生先で捨てられたので、もふもふ達とお料理します~お飾り王妃はマイペースに最強です~

I was abandoned in my reincarnation, so I'll cook with the fluffers - the ornamental queen is the strongest at her own pace!

amzn.to
The work introduced here follows the pattern of gaining allies through cooking, which is common in otherworldly reincarnations. The combination of this with a love of "Mof-Mof" makes for a lighthearted success story that moves along quickly and smoothly.
This work has been changed to "R" from the second volume.

amzn.to
If you start reading from "R", there is no introduction and you will be confused by the sudden development, so I suggest you start reading from "without R".
The "R" version has a more "Honwaka" style, so it is suitable for those who prefer the style of "R".

転生先で捨てられたので、もふもふ達とお料理します~お飾り王妃はマイペースに最強です~

amzn.to

今回紹介する作品は、異世界転生にありがちの料理で周りを味方につけていくパターンの作品です。そこに「もふもふ」好きという要素もかけ合わさって、さくさくと進むサクセスストーリーとしても軽快に話が進んでいきます。
こちらの作品、2巻目からは「R」としてコミカライズされる方が変更になっております。
amzn.to
「R」から読み始めると導入部分がなくて、いきなりな展開にとまどってしまうので、「Rなし」から読み始めるといいと思います。
そして、「R」の方の絵柄の方がより「ほんわか」していますので、そちらの絵柄がより好みの人向けの作品です。

0歳児スタートダッシュ物語

0-year-old starting story

I would like to introduce a comic adaptation of a novel about a different world (Isekai Tensei or Isekai Tani) that has not yet been made into an anime (as of the time of the blog post).

The term "Isekai Tensei" here refers to cases in which the main character died in Japan and was born as a child in another world, or in a body born as a child in which the memories of the time when he/she lived in Japan were revived. There are cases in which a so-called god intervenes and bestows a benefit (cheat), and there are also cases in which the current knowledge itself is a cheat. Therefore, the original status in another world is a characteristic of Isekai Tensei.

"Isekai Teni" refers to cases where a person is transferred from Japan to another world. In this case, there is no otherworldly status, and the name is usually the same as before birth.

Another world transfer" is when a person is transferred from Japan to another world. In this case, there is no otherworldly status, and the name is usually the same as before birth (?). In this case, the person has no otherworldly status, and his/her name is often the same as his/her name before birth (?).

The following is an example.
amzn.to

The main character, Lilia, was born with memories of her previous life. She is a 0-year-old child of the so-called "reincarnation to another world.
Moreover, that world is a game that she played in her previous life, and she tries to avoid it by any means possible because if she doesn't do so, she will become a villainess.
The picture is cute and there are no erotic elements, so it is safe for those who are not good at such things.

0歳児スタートダッシュ物語

異世界もの(異世界転生や異世界転移)のラノベをコミカライズしたもので、(blog投稿時点で)まだアニメ化されていないものを紹介していきたいと思います。

ここでいう「異世界転生」とは、日本で死んだ主人公が異世界で子供として生まれて、もしくは、子供として生まれた体に、日本で生活していたころの記憶がよみがえったケースを指します。いわゆる神様が介在して恩恵(チート)をさずける場合もあるし、現在の知識そのものがチートの場合もあります。なので異世界での身分というのがもともとあるのが異世界転生の特徴です。

また、「異世界転移」は、日本から異世界に転移させられた場合をいいます。このときは異世界の身分はなく、名前も生前(?)の名前の場合がおおいですね。

今回ご紹介するのは次の作品です。
amzn.to

主人公のリリアは、前世の記憶を持って生まれました。いわゆる「異世界転生」の0歳児です。
しかも、その世界は自分が前世でプレイしていたゲームで、このままでは悪役令嬢になってしまうと、あの手この手でそれを避けようとするのですが、天然やらかし属性があるので無自覚にチート披露してしまうというハートフルストーリーです。
絵柄もかわいいし、エロ要素皆無なので、そういったのが苦手な人にも安心ですね。

たかが子爵嫡男に高貴な人たちがグイグイきて困る@COMIC

Noble people are coming on to a mere Viscount Heir to the throne and it's troubling @COMIC

I would like to introduce a comic adaptation of a novel about a different world (Isekai Tensei or Isekai Tani) that has not yet been made into an anime (as of the time of the blog post).

The term "Isekai Tensei" here refers to cases in which the main character died in Japan and was born as a child in another world, or in a body born as a child in which the memories of the time when he/she lived in Japan were revived. There are cases in which a so-called god intervenes and bestows a benefit (cheat), and there are also cases in which the current knowledge itself is a cheat. Therefore, the original status in another world is a characteristic of Isekai Tensei.

"Isekai Teni" refers to cases where a person is transferred from Japan to another world. In this case, there is no otherworldly status, and the name is usually the same as before birth.

Another world transfer" is when a person is transferred from Japan to another world. In this case, there is no otherworldly status, and the name is usually the same as before birth (?). In this case, the person has no otherworldly status, and his/her name is often the same as his/her name before birth (?).

The following is an example.
amzn.to

The main character is a mob character, not a reincarnated person.
The main character is a mob character and not a reincarnated person.
This is a work in which the protagonist leads a quiet student life, unaware of the existence of otherworldly reincarnationists who dream of a successful route because they know the game scenario, which is a typical game world reincarnation scenario.

たかが子爵嫡男に高貴な人たちがグイグイきて困る@COMIC

異世界もの(異世界転生や異世界転移)のラノベをコミカライズしたもので、(blog投稿時点で)まだアニメ化されていないものを紹介していきたいと思います。

ここでいう「異世界転生」とは、日本で死んだ主人公が異世界で子供として生まれて、もしくは、子供として生まれた体に、日本で生活していたころの記憶がよみがえったケースを指します。いわゆる神様が介在して恩恵(チート)をさずける場合もあるし、現在の知識そのものがチートの場合もあります。なので異世界での身分というのがもともとあるのが異世界転生の特徴です。

また、「異世界転移」は、日本から異世界に転移させられた場合をいいます。このときは異世界の身分はなく、名前も生前(?)の名前の場合がおおいですね。

今回ご紹介するのは次の作品です。
amzn.to

典型的なゲーム世界への異世界転生ものかと思ったら、主人公はいわゆるモブキャラで異世界転生者ではありません。
では、異世界転生者はいないのかといえば、ちゃんと登場します。
異世界転生テンプレなゲームシナリオをしっているからこその成功ルートを夢見る異世界転生者の存在を知らずに、主人公がまったり学生生活をおくる、そんな作品です。

ツンデレ悪役令嬢リーゼロッテと実況の遠藤くんと解説の小林さん

Lieselotte, the tsundere villainess, Endo-kun, the play-by-play commentator, and Kobayashi-san, the commentator.

I would like to introduce a comic adaptation of a novel about a different world (Isekai Tensei or Isekai Tani) that has not yet been made into an anime (as of the time of the blog post).

The term "Isekai Tensei" here refers to cases in which the main character died in Japan and was born as a child in another world, or in a body born as a child in which the memories of the time when he/she lived in Japan were revived. There are cases in which a so-called god intervenes and bestows a benefit (cheat), and there are also cases in which the current knowledge itself is a cheat. Therefore, the original status in another world is a characteristic of Isekai Tensei.

"Isekai Teni" refers to cases where a person is transferred from Japan to another world. In this case, there is no otherworldly status, and the name is usually the same as before birth.

Another world transfer" is when a person is transferred from Japan to another world. In this case, there is no otherworldly status, and the name is usually the same as before birth (?). In this case, the person has no otherworldly status, and his/her name is often the same as his/her name before birth (?).

The following is an example.
amzn.to

In fact, it is not a story about a reincarnation into another world, but about a game player named Endo who is not a reincarnation into another world.
It's a slightly eccentric otherworldly story about game players Endo-kun and Kobayashi-san, who get involved with the characters in the game world in the form of a trust.
Anyway, you can read this work while enjoying the tsundere behavior of the main character, Lieselotte (Rizetan).

ツンデレ悪役令嬢リーゼロッテと実況の遠藤くんと解説の小林さん

異世界もの(異世界転生や異世界転移)のラノベをコミカライズしたもので、(blog投稿時点で)まだアニメ化されていないものを紹介していきたいと思います。

ここでいう「異世界転生」とは、日本で死んだ主人公が異世界で子供として生まれて、もしくは、子供として生まれた体に、日本で生活していたころの記憶がよみがえったケースを指します。いわゆる神様が介在して恩恵(チート)をさずける場合もあるし、現在の知識そのものがチートの場合もあります。なので異世界での身分というのがもともとあるのが異世界転生の特徴です。

また、「異世界転移」は、日本から異世界に転移させられた場合をいいます。このときは異世界の身分はなく、名前も生前(?)の名前の場合がおおいですね。

今回ご紹介するのは次の作品です。

amzn.to

実は、異世界転生で異世界転移でもなくて(おい!!)、ゲームプレイヤーである遠藤くんと小林さんがゲーム世界の登場人物たちに信託という形でかかわっていくちょっと風変わりな異世界ものです。
とにかく、主人公のリーゼロッテ(りぜたん)のツンデレぶりを「うんうん」と楽しみながら読める作品です。

.NET Frameworkから.NET 6への移植は別ソリューションで!

.NET Frameworkで作成していたWPFアプリを.NET 6化しています。
.NET 6用の空のプロジェクトを.NET Frameworkのプロジェクトファイルのあるフォルダに新規に作成して、あとは、プロジェクトに既存のソースコードを追加してビルドが通れば、.NET 6化が完了します。

もちろん、動作時の一部非互換もありますので、ビルドしただけじゃなくて、そのあとにいわゆるシステムテスト的なテストで動作が変わっていないかの検証は必要です。
例えば有名なところだと、.NET 5以降についてはNLSじゃなくてICUが使われるようになった点などがあります。文字列のソートなどでカルチャー指定していないコードだとちょっと注意して動作を確認したほうがいいかもしれません。
グローバリゼーションと ICU | Microsoft Docs

ただし、ほぼ、非互換はないのでいくつかの注意点はありますが、プロジェクトファイルを.NET Framework版と.NET 6版に分けておけば、同じソースコードでそれぞれのビルドが通るようにできますので、移行期間のようなときも別々のソースコードを書いてなどは大筋では不要です。
それでも.NET 6のときのみに必要なコードなどが書きたくなったら

#if NETCOREAPP
#endif

のように「NETCOREAPP」のときのみを指定してあげれば実現できます。

### 問題点
こんな感じですごく順調に移行ができていたのですが、.NET Frameworkのプロジェクトファイルと.NET 6のプロジェクトファイルを同一ソリューションにいれてあげたときに問題が発生しました。
別々のソリューションだったときには問題なかったのですが、同一ソリューションにしてあげるとobjフォルダの中に自動生成される「project.assets.json」ファイルの内容がビルドするプロジェクトに応じた内容に変更されず、後からビルドした方のプロジェクトでビルドエラーが発生するようになるのです。
理由としては、project.assets.jsonの中のtargesに動作フレームワークごとにnugetするバージョンなどが記載されるのですが、これが.NET Frameworkのみか.NET 6のみかのどちらかだけしか生成されず両方を指定したものにならないために、すでにproject.assets.jsonが存在した状態でビルドが正しく行えなくなっているのです。

### 解決方法
現状の解決方法は、ソリューションを分けることです。
project.assets.jsonのtargetに手動で両方とも書いてあげても解決するとは思いますが、なにせ自動生成されるファイルなので、書き換えを防止できないことを考えるとお勧めできません。