git
Block 4.1: Advanced features of git
git commit --amend
Caution
Never do this if you already pushed the commit, as it will re-write history
Instead of staging complete files, you can also stage just a section or selection of your changes.
git add --patch <file>
git add -p <file>
Background: https://giphy.com/gifs/stop-motion-experience-3oriNYjm7cl8MjpszK
You can tag a single commit in git.
v1.2.3
SS23
, WS23
git checkout <tag>
git tag v1.2.3
Note
Tags need to be pushed explicitly via git push --tags
"A Mixed Bag"
> #4: Tags
Background: https://giphy.com/gifs/VeSvZhPrqgZxx2KpOA
Before platforms like GitLab/Hub existed, people collaborated by sending around patches via email.
A patch is essentially a commit exported as a file.
git format-patch <commit/branch>
.patch
files for all commits till targetgit apply <patch-file(s)>
From 265f0c1119113f0f84ebfc047c26ef39f5532e57 Mon Sep 17 00:00:00 2001
From: Jan Simson <git@simson.io>
Date: Wed, 15 Nov 2023 20:10:36 +0100
Subject: [PATCH 1/8] Update slogans
---
docs/.vuepress/config.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js
index 6c61bba..53a76bd 100644
--- a/docs/.vuepress/config.js
+++ b/docs/.vuepress/config.js
@@ -1,6 +1,6 @@
module.exports = {
- title: 'GitLab β€οΈ VuePress',
- description: 'Vue-powered static site generator running on GitLab Pages',
+ title: 'Advanced Git & Gitlab',
+ description: 'An interactive course where you get publish your own website',
base: '/',
dest: 'public'
}
\ No newline at end of file
--
2.39.2 (Apple Git-143)
git format-patch <id>
to create a patch for itgit lfs
Git struggles with large binary files.
git lfs
(large file storage)git stash # Stash changes
git stash list # List stashes
git stash apply # Apply the latest stash
git stash pop # Apply and remove the latest stash
Or in a GUI e.g. VSCode (via GitLens)
git cherry-pick <commit-hash>
git cherry-pick <commit-hash>
Besides normal rebases, you can also do interactive ones, where you get to decide what happens with each commit.
git rebase -i <target>
pick f7f3f6d Change my name a bit
pick 310154e Update README formatting and add blame
pick a5f4a0d Add cat-file
# Rebase 710f0f8..a5f4a0d onto 710f0f8
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
# . message (or the oneline, if no original merge commit was
# . specified). Use -c <commit> to reword the commit message.
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
With git working trees, you can have different different branches from one repository checked out at the same time β each in a different directory
<path>
will be automatically checked for a matching branch / commit / tag
"Moving Work around"
Any Questions?