Add new git tips

This commit is contained in:
ben
2025-10-17 20:39:30 +02:00
parent eefeae57ae
commit 0d2198b3e1
2 changed files with 39 additions and 1 deletions

View File

@@ -0,0 +1,19 @@
#!/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}"

View File

@@ -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 <chemin_du_dépot> <commande_git>
@@ -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" <commit_hash>
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
```