20211202のGitに関する記事は3件です。

Git環境で独自のコマンドを登録する【zsh, bash】

はじめに Railsで開発するならbundle e rails (省略)とかめちゃくちゃ使用します。 私はgit pull origin feature/add-watch-modelとか当たりまえのようにタイピングしてました。 そして今更ですがaliasで独自コマンドを設定したので1人でも誰かの役にたてば良いな と思って記事にしました。 参考記事 環境 shell: zsh 独自コマンド登録方法 とりあえず下記で登録できます。 alias g='git' でもターミナルを閉じたり分割すると使用できなくなります なのでシェルの設定ファイルに書き込みます シェルの設定ファイルへ書き込む だいたいの人はbashかzshを使用していると思いますので下記のコマンドで設定ファイルを開きます vi ~/.zshrc # zshの場合 vi ~/.bashrc # bashの場合 aliasを設定する(ちなみに私の設定内容です) iを押してINSERTモードにします # aliasの設定 alias ll='ls -l' alias la='ls -la' alias ..='cd ..' alias ...='cd ../..' alias ....='cd ../../..' alias g='git' alias gs='git status' alias gb='git branch' alias gd='git diff' alias gf='git fetch' alias gc='git commit' alias gch='git checkout' alias ga='git add' alias gcp='git cherry-pick' alias gps='git push origin $(git rev-parse --abbrev-ref HEAD)' alias gpl='git pull origin $(git rev-parse --abbrev-ref HEAD)' alias b='bundle' alias be='bundle exec' alias bi='bundle install' alias bo='bundle outdated' alias bu='bundle update' alias beru='bundle exec rubocop' alias berua='bundle exec rubocop -A' alias ber='bundle exec rspec' alias rc='bundle exec rails c' alias rcs='bundle exec rails c -s' alias rs='bundle exec rails s' alias rg='bundle exec rails generate' alias rr='bundle exec rails routes' alias rdb='bundle exec rails db' alias rmi='bundle exec rails db:migrate' alias rms='bundle exec rails db:migrate:status' alias rmr='bundle exec rails db:migrate:reset' alias v='code .' alias vs='code .' そして:wqで保存します 最後に忘れがちなやつ 下記コマンドで設定を反映させる source ~/.zshrc # zshの場合 source ~/.bashrc # bashの場合 まとめ これで快適になりました。 とくにgit pullやgit pushはめちゃくちゃ楽になりました! 他に便利な独自コマンドがあれば教えて頂けると嬉しいです。
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

githubのリポジトリ言語表示を変更する

背景 Githubのリポジトリ言語がPythonは使ってないのにリポジトリ言語にPythonが表示されていた。 原因 この現象が起きる原因としては1つのライブラリの中にPythonの言語が使われているものがあり、そのせいでリポジトリの主要言語としてPythonが使われいると判断されていたそうです。 解決方法 touch .gitattributes で新しくファイルを作成します。 そこで *[使われしまっている言語名] linguist-language=[変更したい言語名] をすることでリポジトリの言語を変更することができます。
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

gitにcommitするときにブランチからメッセージを追加するメモ

commit-msg #!/bin/sh if [ -n "${GIT_DIR}" ]; then hooksdir="./${GIT_DIR}/hooks/" else hooksdir="./.git/hooks/" fi . "${hooksdir}common.sh" ticket="$(extractTicketId)" if [ -n "${ticket}" ]; then appendMsgTo1stLine "$1" "${ticket}" fi common.sh #! /bin/sh getGitBranchName() { branch="$(git symbolic-ref HEAD 2>/dev/null)" || "$(git describe --contains --all HEAD)" echo ${branch##refs/heads/} } isOnMasterBranch() { if [ "$(getGitBranchName)" = "master" ]; then return 0 fi return 1 } isOnDevelopBranch() { if [ "$(getGitBranchName)" = "develop" ]; then return 0 fi return 1 } isOnFixBranch() { if [[ "$(getGitBranchName)" =~ ^feature/#[0-9]+.* ]]; then return 0 fi return 1 } appendMsgTo1stLine() { mv $1 $1.$$ if [ -s "$1.$$" ]; then if head -1 "$1.$$" | grep "$2" > /dev/null; then cp "$1.$$" "$1" else sed '1s/$/ '"$2"'/' "$1.$$" > $1 fi else echo "$2" > "$1" fi rm -f $1.$$ } extractTicketId() { echo "$(getGitBranchName)" \ | awk 'BEGIN{ FS="[/]"} $1 == "feature" || $1 == "id" { printf "#%s", $2, $3 } $2 == "feature" || $2 == "id" { printf "#%s", $3, $4 } ' } hasTicketId() { first="$(git cat-file -p $1 \ | sed '1,/^$/d' | head -1 \ | sed '/.* #[0-9][0-9]*.*/!d')" if [ -n "${first}" ]; then echo "true" else echo "false" fi } extractParents() { parents="$(git cat-file -p $1 \ | grep '^parent [0-9a-f]\{40\}$')" echo "${parents##parent }" } オリジン2つ登録 git remote add foofoo git@github.com:redamoon/foofoo.git
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む