git cleanup
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
---
|
---
|
||||||
title: "Archives"
|
title: "Archives"
|
||||||
tags: [ "tar", "backups", ".tgz", "tar.gz" ]
|
tags: [ "archives", "backups" ]
|
||||||
---
|
---
|
||||||
# `tar`
|
|
||||||
|
|
||||||
## Create
|
# Create
|
||||||
|
|
||||||
Combine many files and directories into a single t-archive file.
|
Combine many files and directories into a single t-archive file.
|
||||||
|
|
||||||
@@ -35,7 +34,7 @@ files=$(ls /etc/nginx)
|
|||||||
tar cf "$ARCHIVE".tar -C /etc/nginx/ $file
|
tar cf "$ARCHIVE".tar -C /etc/nginx/ $file
|
||||||
```
|
```
|
||||||
|
|
||||||
## Extract
|
# Extract
|
||||||
|
|
||||||
Extract the tar archive with
|
Extract the tar archive with
|
||||||
|
|
||||||
@@ -45,7 +44,7 @@ tar xf "$ARCHIVE".tar
|
|||||||
|
|
||||||
You can remember this with the mnemonic 'e*X*tract *F*ile'.
|
You can remember this with the mnemonic 'e*X*tract *F*ile'.
|
||||||
|
|
||||||
## Compress
|
# Compress
|
||||||
|
|
||||||
Create a zip-compressed archive with the `z` flag.
|
Create a zip-compressed archive with the `z` flag.
|
||||||
|
|
||||||
@@ -55,24 +54,3 @@ tar czf "$ARCHIVE".tgz -C /etc/nginx/ $file
|
|||||||
|
|
||||||
You can use any file ending you want, but sane people like to use '.tgz' or '.tar.tgz'.
|
You can use any file ending you want, but sane people like to use '.tgz' or '.tar.tgz'.
|
||||||
|
|
||||||
# 7zip
|
|
||||||
|
|
||||||
(also called 'p7zip' or '7z')
|
|
||||||
|
|
||||||
Make archive:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
7za a -tzip -p "$PASSWORD" -mem=AES256 $ARCHIVE.zip $FILE_1 $FILE_2
|
|
||||||
```
|
|
||||||
|
|
||||||
Note that people can still see every filename in your archive, and can change those files.
|
|
||||||
They just can't read the contents.
|
|
||||||
|
|
||||||
Unzip:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
7za x archive.zip
|
|
||||||
```
|
|
||||||
|
|
||||||
7zip will open anything: zip-files, rar-files, a tin of beans, *anything*.
|
|
||||||
However, the extracted tgz files will just be tar files, so you will still need to use tar to extract them (see above).
|
|
||||||
131
data/git.md
Normal file
131
data/git.md
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
---
|
||||||
|
title: "git"
|
||||||
|
tags: [ "data", "setup" ]
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git config --global user.email "${email}"
|
||||||
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git config --global user.name "${name}"
|
||||||
|
```
|
||||||
|
|
||||||
|
Decide on algorithm:
|
||||||
|
|
||||||
|
- If you're scared of insecure hash-sums, go with `hash=sha256`.
|
||||||
|
- If you don't know what a hash sum is, go with `hash=sha1`.
|
||||||
|
|
||||||
|
## Init the Git
|
||||||
|
|
||||||
|
Start a git in directory `${DIR}`:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git init --object-format=${hash} ${DIR}
|
||||||
|
cd ${dir}/
|
||||||
|
```
|
||||||
|
|
||||||
|
Make a file explaining what the project does, and tell `git` to track it:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
echo "I hereby solemnly swear never to commit a binary file." > README.md
|
||||||
|
git add README.md
|
||||||
|
```
|
||||||
|
|
||||||
|
Then make the initial commit, explaining the change you just made:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git commit
|
||||||
|
```
|
||||||
|
|
||||||
|
# Working
|
||||||
|
|
||||||
|
Once you make a change to some file, add it and make a commit explaining it.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git add ${file}
|
||||||
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git commit -m"change ${file}"
|
||||||
|
```
|
||||||
|
|
||||||
|
Check your history:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git log
|
||||||
|
```
|
||||||
|
|
||||||
|
# Remotes
|
||||||
|
|
||||||
|
If you want to keep a copy on a public site such as Gitlab, so others can see it, then go there and create a blank project (no readme, nothing).
|
||||||
|
Give it the same name as the `$DIR` directory, above.
|
||||||
|
|
||||||
|
Add this as a remote:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
remote=gitlab
|
||||||
|
git remote add ${remote} https://gitlab.com/${username}/${dir}
|
||||||
|
```
|
||||||
|
|
||||||
|
Tell git you're pushing the branch 'master' to the remote repo 'origin':
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git push -u master origin
|
||||||
|
```
|
||||||
|
|
||||||
|
Pull down changes that others have made:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git pull
|
||||||
|
```
|
||||||
|
|
||||||
|
# Branches
|
||||||
|
|
||||||
|
A branch is a full copy of the project to test additional ideas.
|
||||||
|
You can make a new branch called 'featurez' like this:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git branch ${feature_branch}
|
||||||
|
```
|
||||||
|
|
||||||
|
Have a look at all your branches:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git branch
|
||||||
|
```
|
||||||
|
|
||||||
|
Switch to your new branch:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git checkout ${feature_branch}
|
||||||
|
```
|
||||||
|
|
||||||
|
And if your changes are rubbish, checkout the "master" branch again, then delete "featurez":
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git branch -D ${feature_branch}
|
||||||
|
```
|
||||||
|
|
||||||
|
Or if it's a good branch, push it to the remote:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
remote=origin
|
||||||
|
git push $remote ${feature_branch}
|
||||||
|
```
|
||||||
|
|
||||||
|
# Merging
|
||||||
|
|
||||||
|
Once you like the feature, merge it into the main branch. Switch to master then merge it:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git merge ${feature_branch}
|
||||||
|
```
|
||||||
|
|
||||||
|
And delete the branch, as you've already merged it:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git branch -d ${feature_branch}
|
||||||
|
```
|
||||||
|
|
||||||
@@ -1,202 +0,0 @@
|
|||||||
---
|
|
||||||
title: "git"
|
|
||||||
tags: [ "data" ]
|
|
||||||
---
|
|
||||||
# Starting
|
|
||||||
|
|
||||||
## New Machines
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git config --global user.email "$YOUR_EMAIL"
|
|
||||||
```
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git config --global user.name "$YOUR_NAME"
|
|
||||||
```
|
|
||||||
|
|
||||||
# New Git
|
|
||||||
|
|
||||||
Decide on algorithm:
|
|
||||||
|
|
||||||
- If you're scared of insecure hash-sums, go with `hash=sha256`.
|
|
||||||
- If you don't know what a hash sum is, go with `hash=sha1`.
|
|
||||||
|
|
||||||
## Init the Git
|
|
||||||
|
|
||||||
Start a git in directory `${DIR}`:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git init --object-format=${hash} ${DIR}
|
|
||||||
cd ${DIR}
|
|
||||||
```
|
|
||||||
|
|
||||||
Make a file explaining what the project does, and tell `git` to track it:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
echo "I hereby solemnly swear never to commit a binary file." > README.md
|
|
||||||
git add README.md
|
|
||||||
```
|
|
||||||
|
|
||||||
Then make the initial commit, explaining the change you just made:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git commit
|
|
||||||
```
|
|
||||||
|
|
||||||
# Working
|
|
||||||
|
|
||||||
Once you make a change to some file, add it and make a commit explaining it.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git add $FILE
|
|
||||||
```
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git commit -m"change $FILE"
|
|
||||||
```
|
|
||||||
|
|
||||||
Check your history:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git log
|
|
||||||
```
|
|
||||||
|
|
||||||
# Remotes
|
|
||||||
|
|
||||||
If you want to keep a copy on a public site such as Gitlab, so others can see it, then go there and create a blank project (no readme, nothing).
|
|
||||||
Give it the same name as the `$DIR` directory, above.
|
|
||||||
|
|
||||||
Add this as a remote:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
REMOTE=gitlab
|
|
||||||
git remote add $REMOTE https://gitlab.com/$USERNAME/$DIR
|
|
||||||
```
|
|
||||||
|
|
||||||
Tell git you're pushing the branch "master" to the remote repo "origin":
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git push -u master origin
|
|
||||||
```
|
|
||||||
|
|
||||||
If someone makes a change on the remote, pull it down with:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git pull
|
|
||||||
```
|
|
||||||
|
|
||||||
# Branches
|
|
||||||
|
|
||||||
A branch is a full copy of the project to test additional ideas.
|
|
||||||
You can make a new branch called 'featurez' like this:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git branch $FEATURE_BRANCH
|
|
||||||
```
|
|
||||||
|
|
||||||
Have a look at all your branches:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git branch
|
|
||||||
```
|
|
||||||
|
|
||||||
Switch to your new branch:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git checkout $FEATURE_BRANCH
|
|
||||||
```
|
|
||||||
|
|
||||||
And if your changes are rubbish, checkout the "master" branch again, then delete "featurez":
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git branch -D $FEATURE_BRANCH
|
|
||||||
```
|
|
||||||
|
|
||||||
Or if it's a good branch, push it to the remote:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
remote=origin
|
|
||||||
git push $remote $FEATURE_BRANCH
|
|
||||||
```
|
|
||||||
|
|
||||||
## Merging
|
|
||||||
|
|
||||||
Once you like the feature, merge it into the main branch. Switch to master then merge it:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git merge $FEATURE_BRANCH
|
|
||||||
```
|
|
||||||
|
|
||||||
And delete the branch, as you've already merged it:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git branch -d $FEATURE_BRANCH
|
|
||||||
```
|
|
||||||
|
|
||||||
# Subtree
|
|
||||||
|
|
||||||
## Pulling another git repo into a subtree
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git subtree add -P config git@gitlab.com:bindrpg/config.git master
|
|
||||||
```
|
|
||||||
|
|
||||||
# Tricks
|
|
||||||
|
|
||||||
## Delete All History
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git checkout --orphan temp
|
|
||||||
```
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git add -A
|
|
||||||
```
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git commit -am "release the commits!"
|
|
||||||
```
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git branch -D master
|
|
||||||
```
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git branch -m master
|
|
||||||
```
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git push -f origin master
|
|
||||||
```
|
|
||||||
|
|
||||||
Gitlab requires more changes, such as going to `settings > repository` and switching the main branch, then stripping protection.
|
|
||||||
|
|
||||||
## Clean up Bloated Repo
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git fsck --full
|
|
||||||
```
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git gc --prune=now --aggressive
|
|
||||||
```
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git repack
|
|
||||||
```
|
|
||||||
|
|
||||||
## Find Binary Blobs
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git rev-list --objects --all \
|
|
||||||
| git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' \
|
|
||||||
| sed -n 's/^blob //p' \
|
|
||||||
| sort --numeric-sort --key=2 \
|
|
||||||
| cut -c 1-12,41- \
|
|
||||||
| $(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
# More
|
|
||||||
|
|
||||||
For big binary files (like images), see [git large-file-storage](git-lfs.md)
|
|
||||||
19
data/git/cleanup.md
Normal file
19
data/git/cleanup.md
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
---
|
||||||
|
title: "Clean up a bloated git repo"
|
||||||
|
tags: [ "data", "setup" ]
|
||||||
|
requires: [ "git" ]
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git fsck --full
|
||||||
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git gc --prune=now --aggressive
|
||||||
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git repack
|
||||||
|
```
|
||||||
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
---
|
---
|
||||||
title: "Commit for Another"
|
title: "Commit for Another"
|
||||||
tags: [ "data", "git" ]
|
tags: [ "data", "git" ]
|
||||||
|
requires: [ "git" ]
|
||||||
---
|
---
|
||||||
|
|
||||||
You can make Alice the author, while you are still the commiter:
|
You can make Alice the author, while you are still the commiter:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: "git-secret"
|
title: "git-secret"
|
||||||
tags: [ "data", "git" ]
|
tags: [ "data", "git", "review" ]
|
||||||
---
|
---
|
||||||
|
|
||||||
This utility is largely useless, as it can only identify people by their email.
|
This utility is largely useless, as it can only identify people by their email.
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ tags: [ "data", "git" ]
|
|||||||
Check out the sample hooks:
|
Check out the sample hooks:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
cd $GIT_REPO
|
cd ${git_repo}
|
||||||
ls .git/hooks
|
ls .git/hooks
|
||||||
head .git/hooks/pre-commit.sample
|
head .git/hooks/pre-commit.sample
|
||||||
```
|
```
|
||||||
@@ -21,7 +21,9 @@ chmod u+x .git/hooks/commit-msg
|
|||||||
|
|
||||||
## Committing
|
## Committing
|
||||||
|
|
||||||
Your `git hooks` will not enter the repository, but you can commit them to a repository, then request others add these git hooks to their own branch, by putting a note in the project's `README.md`.
|
The `git hooks` will not work on other people who use the repository, but you
|
||||||
|
can commit them to a repository, then request others add these git hooks to
|
||||||
|
their own branch, by putting a note in the project's `README.md`.
|
||||||
|
|
||||||
```markdown
|
```markdown
|
||||||
The project comes with recommended git hooks.
|
The project comes with recommended git hooks.
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
---
|
|
||||||
title: "git subtree"
|
|
||||||
tags: [ "data", "git", "subtree" ]
|
|
||||||
---
|
|
||||||
|
|
||||||
## Pulling a Subtree from an existing git
|
|
||||||
|
|
||||||
The project has subdirectories `sub-1`, `sub-2`, `sub-3`.
|
|
||||||
The first should be its own repository, but should also retain its own history.
|
|
||||||
|
|
||||||
First, we extract its history as an independent item, and make that into a seprate branch.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git subtree split --prefix=sub-1 -b sub
|
|
||||||
```
|
|
||||||
|
|
||||||
If you want something a few directories deep, you can use `--prefix=sub-1/dir-2/dir-3
|
|
||||||
|
|
||||||
Then go and create a new git somewhere else:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
cd ..;mkdir sub-1;cd sub-1;git init --bare
|
|
||||||
```
|
|
||||||
|
|
||||||
Then go back to your initial git repo, and do the following:
|
|
||||||
|
|
||||||
git push ../subtest sub:master
|
|
||||||
|
|
||||||
Finally, you can clone this repo from your original.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git clone ../subtest
|
|
||||||
```
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user