User Tools

Site Tools


git

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
git [2023/03/16 09:58] skipidargit [2023/11/30 09:11] (current) – [Remove unreachable blobs] skipidar
Line 69: Line 69:
 </code> </code>
  
-{{http://i520.photobucket.com/albums/w327/schajtan/2016-04-11_07-54-14_zpst9gauhtu.png}}+{{https://s3.eu-central-1.amazonaws.com/alf-digital-wiki-pics/sharex/nkP1CdUbXS.png}}
  
  
Line 111: Line 111:
  
  
-==== Initial Setup =====+==== Initial Setup on Windows =====
  
-Store the data in "C:\Users\<USERNAME>\.gitconfig"+== .gitconfig == 
 + 
 +File:  
 +''C:\Users\<USERNAME>\.gitconfig'' 
 + 
 +You can use the cmd to config git. 
 +Tell it the default user name / mail
  
 <code> <code>
Line 119: Line 125:
 git config --global user.email johndoe@example.com git config --global user.email johndoe@example.com
 </code> </code>
 +
 +== .ssh\config ==
 +
 +File: 
 +''C:\Users\<USERNAME>\.ssh\config''
 +
 +Configure ssh to use e.g. the github-key for github url.
 +
 +  * Use the ''/'' notation to point git to the place where you keep the keys. I keep them in my back-up folder.
 +  * Use quotes ''"'' especially if you have empty spaces.
 +
 +
 +<sxh shell>
 +Host github.com
 +    Hostname github.com
 +    User git
 +    IdentityFile "/C/YOUR PATH TO KEY FOLDER/_KEYS/Github/github-privateKey"
 +</sxh>
 +
  
  
Line 181: Line 206:
 </code> </code>
  
- 
-===Assembla=== 
-**Summary:** 
-  - Assembla has SSH Key authtication. It can be generated with Putty - the public key is uploaded here: https://www.assembla.com/user/edit/edit_git_settings 
-  - Then you should create a remote entry with yout Assembla email and private key under <code>TortoiseGit> Setting> Git> Remote  </code> 
-  - Do the "Git Clone" somehwere 
- 
-The details are here: http://blog.assembla.com/assemblablog/tabid/12618/bid/77264/Setting-Up-Git-on-Windows-in-Four-Easy-Steps.aspx 
  
  
Line 222: Line 239:
  
  
-overwriting the remote history in GIT repo+ 
 +==== overwriting the remote history in GIT repo ==== 
 + 
 +overwriting the remote history in GIT repo with commitId 9718422f4b79189c708d95f3302ce95f0bd10631
  
 <code> <code>
 +# find your commit id 9718422f4b79189c708d95f3302ce95f0bd10631
 +git log
 +
 git reset --hard 9718422f4b79189c708d95f3302ce95f0bd10631 git reset --hard 9718422f4b79189c708d95f3302ce95f0bd10631
  
 git push --force-with-lease git push --force-with-lease
 +
 </code> </code>
 +
 +
 +==== Rebase =====
 +
 +<sxh shell>
 +
 +
 +# AT THE BEGINNING make sure you pushed all your local changes before you start
 +
 +# executing commands below is basically equivalent to fresh "git clone"
 +
 +# resets the current branch tip, and also deletes any changes in the working directory and staging area.
 +git reset --hard
 +
 +# make sure you’re in the correct branch
 +git checkout "feat/adr-db-eco-0238-onboarding-service-device-enriched-api"
 +
 +# This will remove all local untracked files, so only git tracked files remain
 +git clean -fdx
 +
 +
 +
 +# make sure, that the "local repository" is up to date
 +git fetch origin main --verbose
 +
 +
 +
 +
 +# see https://docs.gitlab.com/ee/topics/git/git_rebase.html
 +# now rebase it against main
 +# prefer "origin/main" changes during conflicts
 +git rebase -Xtheirs origin/main
 +
 +
 +# Here I found conflict :( between Ola's changes on the swagger integration and changes made by Remy
 +# so I switched to the UI "TortoiseGit" to resolve em..
 +
 +# continued rebasing after the resolution
 +# reapedly till no conflicts
 +git rebase --continue
 +
 +
 +# finally overwrite the remote history with the new rebased one
 +git push --force-with-lease
 +
 +</sxh>
 +
 +
 +==== Getting rid of Git History =====
 +
 +https://stackoverflow.com/questions/13716658/how-to-delete-all-commit-history-in-github
 +
 +<sxh shell>
 +
 +
 +#  first backup your history by copying the branch.
 +#  can remove it later
 +git switch master
 +git branch master_history_2023_11_31
 +git push origin -u master_history_2023_11_31
 +
 +
 +
 +
 +# Checkout as orphan, without history
 +git checkout --orphan latest_branch
 +
 +# Add all the files
 +git add -A
 +
 +# Commit the changes
 +git commit -am "commit message"
 +
 +# Delete the branch
 +git branch -D master
 +
 +# Rename the current branch to master
 +git branch -m master
 +
 +# Finally, force update your repository
 +git push -f origin master
 +
 +
 +</sxh>
 +
 +
 +
 +
 +==== Deleting branch  =====
 +
 +Delete branch ''latest_branch''
 +
 +<sxh shell>
 +
 +git branch -D latest_branch
 +
 +git push origin --delete latest_branch
 +
 +</sxh>
 +
 +
 +
 +==== Remove unreachable blobs, reduce size of repo  =====
 +
 +''objects/pack'': This folder contains packed object files. Git occasionally compresses objects into packfiles to save space and improve performance.
 +
 +
 +Sometimes in ''objects/pack'' there are blobs collected.
 +Even if you removed the history on the current branch, they might persist blowing up the repo.
 +
 +To clean them up - use the garbage collector.
 +
 +<sxh shell>
 +
 +# This command is used to expire all entries in the reflog that are not reachable from the current commit (i.e., entries that are not part of any branch or tag). The --expire-unreachable=all flag specifies that even unreachable entries (such as commits that were "lost" due to being orphaned or removed by a rebase or reset) should be expired. 
 +# The --all flag ensures that it applies to all branches and tags, not just the current branch.
 +git reflog expire --expire-unreachable=all --all
 +
 +
 +
 +# This command triggers Git's garbage collection process (gc stands for "garbage collect"). The --prune=all flag tells Git to aggressively prune all unreachable objects, including unreferenced commits, blobs, trees, and other data that are not reachable from any branch, tag, or reflog entry. This helps to reclaim disk space by removing unnecessary or dangling objects from the repository.
 +
 +git gc --prune=all
 +</sxh>
git.1678960706.txt.gz · Last modified: by skipidar