git – matoken's blog https://matoken.org/blog Is there no plan B? Wed, 01 Jan 2025 09:11:46 +0000 ja hourly 1 https://wordpress.org/?v=6.9.1 https://matoken.org/blog/wp-content/uploads/2025/03/cropped-1865f695c4eecc844385acef2f078255036adccd42c254580ea3844543ab56d9-32x32.jpeg git – matoken's blog https://matoken.org/blog 32 32 細い回線でgit cloneに失敗 https://matoken.org/blog/2024/12/30/git-clone-fails-on-thin-line/ https://matoken.org/blog/2024/12/30/git-clone-fails-on-thin-line/#comments Sun, 29 Dec 2024 15:07:27 +0000 https://matoken.org/blog/?p=4307

細めの回線でgit cloneに失敗することがよくあります.
例えばこんな.

$ git clone https://github.com/ergochat/ergo
Cloning into 'ergo'...
remote: Enumerating objects: 26435, done.
remote: Counting objects: 100% (620/620), done.
remote: Compressing objects: 100% (163/163), done.
error: RPC failed; curl 18 transfer closed with outstanding read data rem
aining
error: 3971 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output

とかこんな

$ git clone https://github.com/ghostty-org/ghostty --depth=1
Cloning into 'ghostty'...
remote: Enumerating objects: 914, done.
remote: Counting objects: 100% (914/914), done.
remote: Compressing objects: 100% (833/833), done.
error: RPC failed; curl 56 GnuTLS recv error (-9): Error decoding the received TLS packet.
error: 3243 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output

git configで以下のような設定で多少ましになりますがそれでも同じリポジトリでも成功したり失敗したりと安定しません.

http.version=HTTP/1.1
http.postbuffer=524288000

clone時に --depth 1 を指定して fetch で段階的に取得することでうまく行くこともありますが面倒.更に試行錯誤で結構データ量も消費してしまいます.

$ git clone http://example.com/large-repository --depth 1 (1)
$ cd large-repository
$ git fetch --depth=64 (2)
$ git fetch --depth=128
$ git fetch --depth=192
$ git fetch --depth=256
   :
$ git fetch --unshallow (3)
  1. 最新1世代だけclone

  2. 最新から64世代clone

  3. 残り全てclone

でも安定しないし毎回試行錯誤が必要なので手元の環境では結局リモートのVPS等で取得してrsyncなどで同期するのが確実です.

oracleの無料なCloud Free TierのVPSでgit cloneしてrsync
$ ssh oracle-arm "git -C /tmp/ clone https://github.com/ergochat/ergo" && \
  ssh rsync -avcP /tmp/ergo . && \
  ssh oracle-arm "rm -r /tmp/ergo"

もしくは太い回線のある場所に移動してclone.自分の場合は自宅の隣のmobile cellやJoyfullです.

ちなみにこの症状の出る回線は最大7Mbpsほどのモバイル回線で,MVNOを使っているのも利いていそうです.
LTE]

StarLinkも気になりますが山に囲まれ散るのでうまく電波を掴めるかが不安です.30日以内なら返品可能なようですが…….

30 DAY TRIAL
If not satisfied, return Starlink for a full refund.

Starlink
環境
$ git version
git version 2.45.2
$ dpkg-query -W git
git     1:2.45.2-1.3
$ lsb_release -dr
Description:	Debian GNU/Linux trixie/sid
Release:	n/a
$ arch
x86_64
]]>
https://matoken.org/blog/2024/12/30/git-clone-fails-on-thin-line/feed/ 1
git diff の 差分にだけ ^M が表示される https://matoken.org/blog/2024/08/12/m-is-displayed-only-in-git-diff-differences/ https://matoken.org/blog/2024/08/12/m-is-displayed-only-in-git-diff-differences/#respond Mon, 12 Aug 2024 12:43:00 +0000 https://matoken.org/blog/?p=4080

git diff で変種箇所だけ ^M が付いてるのに気づきました.
編集ミスて改行コードを間違えたかと思ったけど元々 \r\n なファイルで編集箇所以外も同じ \r\n です.
でも非編集箇所は ^M が出ません.


git diff
$ git diff -p
diff --git a/src/onnxstream.cpp b/src/onnxstream.cpp
index 5ace952..bbc62f6 100644
--- a/src/onnxstream.cpp
+++ b/src/onnxstream.cpp
@@ -503,7 +503,7 @@ public:
             throw std::runtime_error("failed to initialize XNNPACK");
     }

-    ~XnnPack()
+    ~XnnPack() noexcept(false)^M (1)
     {
         for (auto& entry : m_ops_cache)
         {
diff --git a/src/onnxstream.h b/src/onnxstream.h
index 6746f61..9c2755a 100644
--- a/src/onnxstream.h
+++ b/src/onnxstream.h
@@ -1,5 +1,6 @@                                                                          e           '
 #pragma once

+#include <algorithm>^M (2)
 #include <limits>
 #include <vector>
 #include <functional>
  1. ここと

  2. ここの編集差分に ^M

od で見ると編集箇所もそれ以外も \r\n になっている
$ head -4 ../../src/onnxstream.h | od -xc
0000000    7023    6172    6d67    2061    6e6f    6563    0a0d    0a0d
          #   p   r   a   g   m   a       o   n   c   e  \r  \n  \r  \n
0000020    6923    636e    756c    6564    3c20    6c61    6f67    6972
          #   i   n   c   l   u   d   e       <   a   l   g   o   r   i
0000040    6874    3e6d    0a0d    6923    636e    756c    6564    3c20
          t   h   m   >  \r  \n   #   i   n   c   l   u   d   e       <
0000060    696c    696d    7374    0d3e    000a
          l   i   m   i   t   s   >  \r  \n
0000071

ということでファイルの内容は問題無さそうですが, git diff の表示上の問題のようです.

検索して以下のページを見つけました.

いろいろな方法が書かれていますが,ちょっと試したいリポジトリなので改行コードを変更するのではなく \M の表示を抑制するようにしたいです.

一番お手軽そうなコマンドラインオプションをいくつか試しましたが以下のオプションはすべて変化が見られませんでした.

git diff のオプション
$ git diff -b
$ git diff --ignore-cr-at-eol
$ git diff --ignore-space-change
$ git diff --ignore-all-space

git-config に whitespace = cr-at-eol を設定してみます. CR/LF のファイルはあまり使うことはないので --local に設定しておきます.

$ git config --local core.whitespace cr-at-eol
$ grep cr-at-eol .git/config
        whitespace = cr-at-eol

この設定をすることで ^M が表示されなくなりました.

$ git diff
diff --git a/src/onnxstream.cpp b/src/onnxstream.cpp
index 5ace952..bbc62f6 100644
--- a/src/onnxstream.cpp
+++ b/src/onnxstream.cpp
@@ -503,7 +503,7 @@ public:
             throw std::runtime_error("failed to initialize XNNPACK");
     }

-    ~XnnPack()
+    ~XnnPack() noexcept(false)
     {
         for (auto& entry : m_ops_cache)
         {
diff --git a/src/onnxstream.h b/src/onnxstream.h
index 6746f61..9c2755a 100644
--- a/src/onnxstream.h
+++ b/src/onnxstream.h
@@ -1,5 +1,6 @@
 #pragma once

+#include <algorithm>
 #include <limits>
 #include <vector>
 #include <functional>
環境
$ git --version
git version 2.45.2
$ dpkg-query -W git
git     1:2.45.2-1
$ lsb_release -dr
Description:    Debian GNU/Linux trixie/sid
Release:        n/a
$ arch
x86_64
]]>
https://matoken.org/blog/2024/08/12/m-is-displayed-only-in-git-diff-differences/feed/ 0
GitWebでリポジトリが404になってしまう https://matoken.org/blog/2023/05/29/gitweb%e3%81%a7%e3%83%aa%e3%83%9d%e3%82%b8%e3%83%88%e3%83%aa%e3%81%8c404%e3%81%ab%e3%81%aa%e3%81%a3%e3%81%a6%e3%81%97%e3%81%be%e3%81%86/ https://matoken.org/blog/2023/05/29/gitweb%e3%81%a7%e3%83%aa%e3%83%9d%e3%82%b8%e3%83%88%e3%83%aa%e3%81%8c404%e3%81%ab%e3%81%aa%e3%81%a3%e3%81%a6%e3%81%97%e3%81%be%e3%81%86/#respond Mon, 29 May 2023 13:19:39 +0000 https://matoken.org/blog/?p=3905

ふとGitWebを起動したら404になって困りました.

$ git instaweb --httpd webrick

gitweb404

$ w3m -dump http://127.0.0.1:1234/
]>
gitprojects /


404 - No projects found
OPML TXT

いくつかのリポジトリで試すと,駄目なのは自分のものだけのようでcloneした他の人の作ったものは動いていそうです.自分おリポジトリに何かが足りない?

と思ったのですが,ddgで検索すると以下のページを見つけました.

Found a likely cause while writing the question: Cloning the repository to a directory without the @ character in the name fixed it.

ディレクトリに@が含まれていると駄目のようです.リポジトリを@の含まれていないところにコピーするとうまく動きました.

$ pwd | grep -o '@'
@
$ git instaweb --httpd webrick --stop
$ cp -a ../05 `mktemp -d`
$ cd /tmp/tmp.LjVifz85dp/05
$ git instaweb --httpd webrick

自分のリポジトリは@の含まれるパスの下にあって,他のcloneしたリポジトリは@の含まれないパスの下にあったので動いていたということのようでした.

環境
$ dpkg-query -W git ruby-webrick
git     1:2.39.2-1.1
ruby-webrick    1.8.1-1
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 12 (bookworm)
Release:        12
Codename:       bookworm
$ arch
x86_64
]]>
https://matoken.org/blog/2023/05/29/gitweb%e3%81%a7%e3%83%aa%e3%83%9d%e3%82%b8%e3%83%88%e3%83%aa%e3%81%8c404%e3%81%ab%e3%81%aa%e3%81%a3%e3%81%a6%e3%81%97%e3%81%be%e3%81%86/feed/ 0
Gitコマンドのデフォルトブランチをmainにする https://matoken.org/blog/2022/05/21/make-git-command-default-branch-main/ https://matoken.org/blog/2022/05/21/make-git-command-default-branch-main/#respond Fri, 20 May 2022 16:21:53 +0000 http://matoken.org/blog/?p=3637

Gitのデフォルトブランチはmasterですが,masterからslaveという言葉を連想して一部に人が不愉快に感じるので使わないようにしようという動きが2年ほど前からあって各種サービスのデフォルトブランチもmainになっています.(witelist/blacklistなんかも)
でも手元のGitコマンドのデフォルトはmasterなので既定値を変更してみました.

まず普通にリポジトリを作るとmasterになります.ただ,ヒントは表示されます.
git branch -m <新しいブランチ名> でブランチ名の変更ができました.

$ cd /tmp/tmp.07sONCJp59
$ git init
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /tmp/tmp.07sONCJp59/.git/
$ git status
On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)
$ echo test > test
$ git add test
$ git commit -m 'test'
[master (root-commit) c27747d] test
 1 file changed, 1 insertion(+)
 create mode 100644 test
$ git branch
$ PAGER=cat git branch
* master
$ git branch -m master main
$ PAGER=cat git branch
* main
$ git log
$ tig
$ echo main > main
$ git add main
$ git commit -m 'mainにしてからの初めてのコミット'
[main dc3230d] mainにしてからの初めてのコミット
 1 file changed, 1 insertion(+)
 create mode 100644 main
$ git status
On branch main
nothing to commit, working tree clean

デフォルトブランチを変更してみます.

man git-config より init.defaultBranch で変更できそうです.

init.defaultBranch
    Allows overriding the default branch name e.g. when initializing a new repository.

実際に設定してみます.
git config --global init.defaultBranch main でデフォルトブランチを main に設定して ~/.gitconfig に設定されているのを確認,実際にリポジトリを作ると main になりました.

$ mktemp -d
/tmp/tmp.QBuop4f5Vn
$ cd /tmp/tmp.QBuop4f5Vn
$ git config --global init.defaultBranch main
$ grep Branch ~/.gitconfig
        defaultBranch = main
$ git init
Initialized empty Git repository in /tmp/tmp.QBuop4f5Vn/.git/
$ PAGER=cat git branch
$ echo test > test
$ git add test
$ git commit -m '1st commit'
[main (root-commit) dfe208a] 1st commit
 1 file changed, 1 insertion(+)
 create mode 100644 test
$ git status
On branch main
nothing to commit, working tree clean
$ PAGER=cat git branch
* main
環境
$ dpkg-query -W git
git     1:2.36.1-1
$ lsb_release -dr
Description:    Debian GNU/Linux bookworm/sid
Release:        unstable
$ arch
x86_64
]]>
https://matoken.org/blog/2022/05/21/make-git-command-default-branch-main/feed/ 0
GitLabのデフォルトブランチ切り替えと削除 https://matoken.org/blog/2022/05/15/gitlab-default-branch-switching-and-removal/ https://matoken.org/blog/2022/05/15/gitlab-default-branch-switching-and-removal/#comments Sun, 15 May 2022 09:16:22 +0000 http://matoken.org/blog/?p=3633

GitLabで空のリポジトリを作成するとmainブランチが作られ,ローカルのmasterブランチのリポジトリをpushしても反映されない?と混乱するというのをやっていました.
とりあえずGitLabでデフォルトブランチを変更して空のmainブランチを削除しました.

ローカルのリポジトリはmasterで,GitLabは空のmainとpushされたmasterがある状態です.
デフォルトブランチはmainになっていてリポジトリのtopページは空の状態です.ブランチをmasterにするとmasterブランチを見ることができます.

デフォルトブランチの切り替え

デフォルトブランチをmasterに切り替えます.

  • 該当リポジトリ→設定→リポジトリの設定→デフォルトブランチ→master

これでリポジトリのトップページでmasterブランチが表示されるようになりました.

不要なブランチの削除

次に空で使わないmainブランチを削除します.

  • 該当リポジトリ→ブランチ→main→🗑

GitLabの空リポジトリをローカルでmasterに変更

GitLabで空のリポジトリをローカルにcloneしてブランチをmasterに変更してpushすることでGitLabの操作を必要とせずブランチ切り替えが可能でした.新規の場合はこれのほうがいいかもしれません.

$ git clone git@gitlab.com:matoken/blogtest.git
$ cd blogtest
$ git status
On branch main

No commits yet

nothing to commit (create/copy files and use "git add" to track)
$ git switch -c master
Switched to a new branch 'master'
$ echo "GitLab branch test." > README.txt
$ git add README.txt
$ git commit -m 'add README.txt'
[master (root-commit) 6437831] add README.txt
 1 file changed, 1 insertion(+)
 create mode 100644 README.txt
$ git push -u origin master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 898 bytes | 898.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To gitlab.com:matoken/blogtest.git
 * [new branch]      master -> master
branch 'master' set up to track 'origin/master'.
]]>
https://matoken.org/blog/2022/05/15/gitlab-default-branch-switching-and-removal/feed/ 1
GitHub.comのリポジトリの特定のディレクトリ以下をダウンロードできる「GitHub clone」 https://matoken.org/blog/2021/03/02/github-clone-which-allows-you-to-download-a-specific-directory-or-less-of-a-repository-from-github-com/ https://matoken.org/blog/2021/03/02/github-clone-which-allows-you-to-download-a-specific-directory-or-less-of-a-repository-from-github-com/#respond Mon, 01 Mar 2021 23:40:47 +0000 http://matoken.org/blog/?p=3029

大きなGitリポジトリをcloneすると時間がかかります.最新のものだけが欲しい場合は --depth オプションがありますが,リポジトリの一部のディレクトリ以下だけが欲しい時には使えません.そういうときにGitHub cloneを使うと,特定のディレクトリ以下だけをダウンロードできて便利そうです.

少し試してみました.

$ pip3 install git+git://github.com/HR/github-clone#egg=ghclone (1)
$ ghclone (2)
Usage:
  ghclone <url> [-t | --token=<token>]
  ghclone (-h | --help)
  ghclone (-v | --version)
$ ghclone https://github.com/torvalds/linux/tree/master/tools/usb/usbip (3)
Cloning into 'usbip'...
done.
$ cd usbip
$ ls -A (4)
.gitignore  AUTHORS  COPYING  INSTALL  Makefile.am  README  autogen.sh  cleanup.sh  configure.ac  doc  libsrc  src  vudc
$ git status (5)
fatal: not a git repository (or any of the parent directories): .git
$ cd ..
$ ghclone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/usb (6)
Invalid GitHub URI
  1. pipで導入する(もしPATHが通ってなければ ~/.local/bin を加える)
  2. USAGE
  3. Linux Kernelの一部だけをダウンロード
  4. ダウンロード内容確認
  5. Git管理はされていない
  6. GitHub以外のGitリポジトリに対して実行すると失敗する

GitHub.comのAPIを利用しているのでGitHub.com以外では使えませんが便利そうです.

似たものにBitBacketで同様のことができる,「bb-clone」というものもあるようです.

環境
$ ghclone -v
1.2.0
$ dpkg-query -W git python3-pip python3
git     1:2.20.1-2+deb10u3
python3 3.7.3-1
python3-pip     18.1-5+rpt1
$ lsb_release -dr
Description:    Raspbian GNU/Linux 10 (buster)
Release:        10
$ uname -a
Linux raspberrypi 5.10.11-v7+ #1399 SMP Thu Jan 28 12:06:05 GMT 2021 armv7l GNU/Linux
$ cat /proc/device-tree/model ;echo
Raspberry Pi 3 Model B Rev 1.2
]]>
https://matoken.org/blog/2021/03/02/github-clone-which-allows-you-to-download-a-specific-directory-or-less-of-a-repository-from-github-com/feed/ 0
Git学習ゲームの「Oh My Git!」 https://matoken.org/blog/2021/02/11/git-learning-game-oh-my-git/ https://matoken.org/blog/2021/02/11/git-learning-game-oh-my-git/#respond Thu, 11 Feb 2021 12:12:41 +0000 http://matoken.org/blog/?p=2986
git game01

先週あったFOSDEM 2021のライトニングトーク(といっても1コマ20分)で知ったのですが,「Oh My Git!」というGit学習ゲームがあるそうです.

マルチプラットホームでWindows/macOS/Linux版が用意されています.バイナリはitch.ioで入手できます.

Note
itch.ioについてはこのあたりを.

ゲーミングプラットホームのitch – Speaker Deck

お題が出てきて,それにあった操作のカードを切ってgitの操作をしていきます.実際のコマンド内容も表示され,リポジトリも実際にローカルマシンに作られます.

git game02

ツリーがグラフィックで表現されてわかりやすいしキーボードに慣れていない人でもカードで操作だし入門に良さそうな感じです.後はローカライズされると勧めやすくなるかな.

]]>
https://matoken.org/blog/2021/02/11/git-learning-game-oh-my-git/feed/ 0