Skip to content

Instantly share code, notes, and snippets.

@kiurtis
Last active March 23, 2023 09:14
Show Gist options
  • Save kiurtis/35cad3ef3be0e90509a53d3912a110b5 to your computer and use it in GitHub Desktop.
Save kiurtis/35cad3ef3be0e90509a53d3912a110b5 to your computer and use it in GitHub Desktop.
#### Get list of objects by size ####
# work over each commit and append all files in tree to $tempFile
tempFile=$(mktemp)
IFS=$'\n'
for commitSHA1 in $(git rev-list --all); do
git ls-tree -r --long "$commitSHA1" >>"$tempFile"
done
# sort files by SHA1, de-dupe list and finally re-sort by filesize
sort --key 3 "$tempFile" | \
uniq | \
sort --key 4 --numeric-sort --reverse
# remove temp file
rm "$tempFile"
####
#### Move uncommitted changes on master to another branch ####
# From: https://stackoverflow.com/questions/14506910/git-move-changes-off-of-master-branch
# How to move the changes into a new branch new-working-branch and then discard working-branch
git checkout -b new-working-branch
git add …
git commit -m "mycommit"
#As you didn’t commit anything to master yet, you don’t need to change anything on master. You can now discard your working-branch if you feel like it.
# How to move the changes over to working-branch
## Works in any case:
git checkout -b temp-branch
git add …
git commit -m "mycommit"
git rebase --onto working-branch master
git checkout working-branch
git reset --hard temp-branch
git branch -d temp-branch
## If your changes don’t conflict with any changes that are on master, but not in working-branch, this can be done a lot simpler:
git stash
git checkout working-branch
git stash pop
#### Count number of commit in branch_A not in branch_B ####
git rev-list --count branch_A ^branch_B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment