hackade.org/ wiki/ shell/ commands/ Git

Exécuter git depuis un autre répertoire que celui du dépôt:

git -C <chemin_du_dépot> <commande_git>

Commandes pour une configuration de base dans un dépôt:

git config user.name ben
git config user.email ben@nospam.org
git config core.editor vim

Commandes pour une configuration pour tous les dépôt:

git config --global user.name ben
git config --global user.email ben@nospam.org
git config --global core.editor vim

Copier un commit d'un dépôt à un autre:

cd repo_origin
git format-patch --output-directory "/home/user/git-patches" <commit_hash>
cd repo_dest
git am /home/user/git-patches/0001-xxxxxx.patch

Exporter des commits de manière interactive:

export git commits.sh
#!/usr/bin/env bash

if [[ $# -ne 1 ]]; then
  echo "Usage: $0 <repo_path>"
  exit 1
fi

REPO_PATH="${1}"
PATCHES_PATH="$(mktemp -d)"

read -r -p 'Select your first commit to export'
FIRST_COMMIT_LINE=$(git -C "${REPO_PATH}" log --pretty=format:'%h: %cn <%ce>, %ah %ar, %s' | fzf)
read -r -p 'Select your last commit to export'
LAST_COMMIT_LINE=$(git -C "${REPO_PATH}" log --pretty=format:'%h: %cn <%ce>, %ah %ar, %s' | fzf)

FIRST_COMMIT_HASH=$(echo "${FIRST_COMMIT_LINE}" | cut -d':' -f1)
LAST_COMMIT_HASH=$(echo "${LAST_COMMIT_LINE}" | cut -d':' -f1)

git -C "${REPO_PATH}" format-patch --output-directory "${PATCHES_PATH}" "${LAST_COMMIT_HASH}~..${FIRST_COMMIT_HASH}"
Posted

Modifier les derniers commits:

git rebase -i HEAD~4