ホーム » gitlab

gitlab」カテゴリーアーカイブ

git tag を追加

タグを追加

[code]
git tag -a タグ名 -m "コメント"
[/code]

タグをリモートリポジトリに反映

[code]
git push origin –tag
[/code]

タグの一覧

[code]
git tag
[/code]

git commit時のメッセージをVisualCodeで入力

予めVisualCodeをインストール

C:\Users\ユーザー名\.gitconfigを開いて以下を追加

[code]
[core]
quotepath = off
editor = "code –wait"
[/code]

git commit 関連

commitの一覧表示

[code]
git log
[/code]

直近のcommitの内容表示

[code]
git log -1
[/code]

直近のcommitの対象ファイル一覧

[code]
git log -1 –name-only
[/code]

直近のcommitの取り消し 編集したファイルは変更しない

[code]
git reset –soft HEAD~
[/code]

[code]
HEAD~とHEAD^は同じ
[/code]

直近のcommitの取り消し 編集したファイルも元に戻す

[code]
git reset –hard HEAD~
[/code]

git add を取り消し

[code]
git reset
[/code]

GIt ローカルリポジトリとリモートリポジトリの同期をとる

ローカルリポジトリとリモートリポジトリの同期をとる(=VSSでは最新バージョンの取得)
はローカルリポジトリ内で以下のコアンドを実行
[code]
git pull origin master
[/code]

指定したファイル、ディレクトリをGitの対象外とする

VsiualStudioで開発をし、ビルドを行うと多くのバイナリファイル、フォルダが作成される。

これらをGitの対象外とするにはリポジトリの直下に「.gitignore」ファイルを作成して、対象外とするファイルとディレクトリを書き込み。

[code]
bin/
obj/
[/code]

GitHubのリポジトリをローカルにClone

前回申し込んだGitHubのリポジトリをローカルにクローンする。

基本的にはgit for windowsをインストールしてgitlabのプロジェクトを操作に記載した内容でOK。
今回は既にGitLabのリポジトリへの接続環境が作成されているPC上にGitHubのリポジトリへの接続環境を構築する。
GITHUBもGITLABと同様にSSHキーを必要とするため以下に従って作成。(保存するファイルはデフォルトではなくgithub_kernel_rsaに変更)

[code]
C:\Git\usr\bin>ssh-keygen -t rsa -C ‘メールアドレス’
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/tarumi/.ssh/id_rsa): /c/Users/tarumi/.ssh/github_kernel_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/tarumi/.ssh/github_kernel_rsa.
Your public key has been saved in /c/Users/tarumi/.ssh/github_kernel_rsa.pub.
The key fingerprint is:
省略
C:\Git\usr\bin>
[/code]

なぜかファイル名が文字化けしていたので修正

GitHubのサイトにSSHキーを登録

GItHubのサイトの「your profile」を表示

「Edit Profile」ボタンを押す

「SSH and GPG keys」を選択し「New SSH Key」ボタンを押す

github_kernel_rsa.pubの内容を貼り付ける

C:\Git\etc\ssh\ssh_configを以下に従って編集
※この設定は複数のGITリポジトリ(GITLABとGITHUB)とアクセスするために設定する

[code]
Host gitlab
User git
Port 22
HostName gitlab.com
TCPKeepAlive yes
identitiesonly yes
identityFile /C/Users/tarumi/.ssh/id_rsa

Host github
User git
Port 22
HostName github.com
TCPKeepAlive yes
identitiesonly yes
identityFile /C/Users/tarumi/.ssh/github_kernel_rsa
[/code]

github上のリポジトリをローカルにクローン

今回はC:\githubhomeディレクトリ以下にローカルリポジトリを作成していく。

通常(ssh_configの設定を使用しない)はgithubのリポジトリサイトを表示し「clone or download」ボタンを押しsshのURLを表示し

以下のコマンドでgithub上のリポジトリをローカルにクローンする。

[code]
git clone git@github.com:組織名/test.git
[/code]

今回(ssh_configの設定を使用)は以下のコマンドでクローンする

[code]
git clone git@github:組織名/test.git
[/code]

上記で指定したgithubはssh_configのHostに指定した値

[code]
C:\githubhome>git clone git@github:組織名/test.git
Cloning into ‘test’…
Enter passphrase for key ‘/C/Users/tarumi/.ssh/github_kernel_rsa’:
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
[/code]

リポジトリのフォルダに移動して以下のコマンドでgitへの接続ユーザーの設定を行う

[code]
C:\>cd githubhome
C:\githubhome>cd test
C:\githubhome\test>git config –local user.email ‘メールアドレス’
C:\githubhome\test>git config –local user.name ‘ユーザー名’
C:\githubhome\test>git config –local core.quotepath off
[/code]
引数に–localを付けたときはローカルリポジトリのフォルダ内のみで有効な設定として保存される。

設定した内容はローカルリポジトリ内の.gitフォルダに保存される

git 既存ファイルを編集

既存のファイルを編集後リモートリポジトリに反映

変更されたファイルをインデックスに追加
[code]
git add -u
[/code]

ファイルをローカルリポジトリにコミット
[code]
git commit -a -m "コメント"
[/code]

ファイルをリモートレポジトリに反映
[code]
git push origin master
Enter passphrase for key ‘/c/Users/tarumi/.ssh/id_rsa’: SSLキーのパスワードを入力
[/code]

git ファイルの追加

プロジェクトディレクトリ以下にファイルを追加した時は以下の操作でリモートのレポジトリに反映する

ファイルをインデックスに追加
[code]
git add .
[/code]

特定のファイルのみを追加
[code]
git add ファイル名
[/code]

インデックスに追加されたファイルをローカルレポジトリにcommit
[code]
git commit -m "コメント"
[/code]

リモートレポジトリに反映

[code]
git push origin master
Enter passphrase for key ‘/c/Users/tarumi/.ssh/id_rsa’:SSLキーのパスワードを入力
[/code]

git for windowsをインストールしてgitlabのプロジェクトを操作

Git for windowsのサイトよりインストーラーをダウンロードし、インストール。
インストーラーは「Git-2.16.2-64-bit.exe」
Windows10の場合はWindowsの設定より「アプリのインストール」を「ストアのアプリのみ許可する」以外を選択しておく

インストーラーを実行して以下に従ってインストール

インストール先のディレクトリはC:\Gitに変更

インストールするコンポーネントはデフォルト

デフォルトのエディタ
※後ほど秀丸に変更の予定

bashではwindowsのDOSを使用

SSLの設定

改行の処理の設定

その他のオプション

インストール終了

Gitの初期設定

DOSコマンドを開きメールアドレス、ユーザー名等を設定
※core.quotepathをoffにするとgit statusで変更ファイル一覧を表示するときに、日本語のファイル名が文字化けしないでちゃんと表示される
ユーザー名、メールアドレスはGitlabに設定した値を入力
[code]
C:\Users\tarumi>git config –global user.email ‘メールアドレス’
C:\Users\tarumi>git config –global user.name ‘ユーザー名’
C:\Users\tarumi>git config –global core.quotepath off
[/code]

SSHのキーを作成
カレントをc:\git\usr\binに移動
以下のコマンドを実行
パスフレーズには任意の値を入力

[code]
C:\Git\usr\bin>ssh-keygen -t rsa -C ‘メールアドレス’
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/tarumi/.ssh/id_rsa):
Created directory ‘/c/Users/tarumi/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:[/code]
[/code]

GitLabのサイトを開きメニューより設定を選択

サイドばーよりSSHきーを選択してSSHキーを入力するページを表示

先ほど作成したid_rsa.pubの内容を張り付ける

以上で設定は終了

最初にプロジェクトのクローンを作成

GitLabで対象のプロジェクトを開き画面上のURLをコピー

PC上にローカルディレクトリを作成してカレントに移動し以下のコマンドを実行

[code]
git clone git@gitlab.comから始まるURL(上記でコピーした値)
[/code]

以上でローカルにcloneが作成される