LoginSignup
2
2

More than 5 years have passed since last update.

gitのやりなおし、特殊ケース

Posted at

Git やりなおし

について、いろいろなケースについて検索したりすると思います。

一般的なケース

これらはQiitaでも

などの記事が参考になりますし、その他いろいろあります。

ちょっと特殊なケース

これについて、気付きのあったものを記載していこうかなと。

commit author

よくあるのは1

$ git commit --amend --author="Tsuyoshi CHO <Tsuyoshi.CHO@Gmail.com>"
# あるいは
$ git filter-branch ...

系ですが、ある記事2により、以下のほうが良さそうだと気付きました。

$ git config --local user.name "Tsuyoshi CHO"
$ git config --local user.email "Tsuyoshi.CHO@Gmail.com"
$ git commit --amend --reset-author

※これについては gitの自分アカウント設定(リポジトリローカル) - Qiita も参照

たしかに、せっかくconfigを直したんだから、その設定でリセットしてほしいですよね。

もし複数あったりしても、現在ブランチを別名を付けてgit checkout -b <another>、その履歴をcherry-pickしつつ直したほうが、問題を考えなくていい分楽かもしれません。

git lfs化

大きなファイルを入れてしまった場合、LFSにしたくて

$ git filter-branch ...

とかで履歴改変をがんばること3になりますが...、記述が面倒なので、子細はリンク先を見てください。

これについて、git lfs migrateを使う4という方法があります。
いつごろ普通に使えるようになってたのかは不明ですが。

こうすると

$ git clone
$ git lfs migrate import --include-ref master --include="*.jpg"
# .gitattributesでのtrack設定がさもあったかのように履歴を改変する

と、改変を自動でやってくれるので、問題が発生しずらいです。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2