From 0d2198b3e1ba7b14595cebe7567023c294d81f06 Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 17 Oct 2025 20:39:30 +0200 Subject: [PATCH] Add new git tips --- code/shell/commands/export_git_commits.sh | 19 +++++++++++++++++++ wiki/shell/commands/Git.mdwn | 21 ++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 code/shell/commands/export_git_commits.sh diff --git a/code/shell/commands/export_git_commits.sh b/code/shell/commands/export_git_commits.sh new file mode 100644 index 0000000..30f12ee --- /dev/null +++ b/code/shell/commands/export_git_commits.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +if [[ $# -ne 1 ]]; then + echo "Usage: $0 " + 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}" diff --git a/wiki/shell/commands/Git.mdwn b/wiki/shell/commands/Git.mdwn index 65ea9ce..eea3af8 100644 --- a/wiki/shell/commands/Git.mdwn +++ b/wiki/shell/commands/Git.mdwn @@ -1,6 +1,6 @@ # Git -## Exécuter git depuis un autre répertoire que celui du dépôt +## Exécuter git depuis un autre répertoire que celui du dépôt: ``` git -C @@ -21,3 +21,22 @@ 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" +cd repo_dest +git am /home/user/git-patches/0001-xxxxxx.patch +``` + +## Exporter des commits de manière interactive: + +[[!inline pages="code/shell/commands/export_git_commits.sh" rss="no" atom="no" feeds="no"]] + +## Modifier les derniers commits: + +``` +git rebase -i HEAD~4 +```