Git CLI hints: Difference between revisions
From WikiMLT
m (Стадий: 4 [Фаза:Авторизиране, Статус:Разработен]; Категория:DevOps and SRE) |
m (Стадий: 5 [Фаза:Утвърждаване, Статус:Авторизиран]; Категория:DevOps and SRE) |
||
Line 65: | Line 65: | ||
{{devStage | {{devStage | ||
| Прндл = DevOps and SRE | | Прндл = DevOps and SRE | ||
| Стадий = | | Стадий = 5 | ||
| Фаза = | | Фаза = Утвърждаване | ||
| Статус = | | Статус = Авторизиран | ||
| ИдтПт = Spas | | ИдтПт = Spas | ||
| РзбПт = Spas | | РзбПт = Spas | ||
| АвтПт = | | АвтПт = Spas | ||
| УтвПт = | | УтвПт = {{REVISIONUSER}} | ||
| ИдтДт = 5.07.2022 | | ИдтДт = 5.07.2022 | ||
| РзбДт = 22.11.2022 | | РзбДт = 22.11.2022 | ||
| АвтДт = | | АвтДт = 22.11.2022 | ||
| УтвДт = | | УтвДт = {{Today}} | ||
| ИдтРв = [[Special:Permalink/27692|27692]] | | ИдтРв = [[Special:Permalink/27692|27692]] | ||
| РзбРв = [[Special:Permalink/32177|32177]] | | РзбРв = [[Special:Permalink/32177|32177]] | ||
| АвтРв = | | АвтРв = [[Special:Permalink/32179|32179]] | ||
| РзАРв = [[Special:Permalink/27711|27711]] | | РзАРв = [[Special:Permalink/27711|27711]] | ||
| УтвРв = {{REVISIONID}} | |||
| РзУРв = [[Special:Permalink/32168|32168]] | | РзУРв = [[Special:Permalink/32168|32168]] | ||
}} | }} | ||
</div> | </div> | ||
</noinclude> | </noinclude> |
Revision as of 14:52, 22 November 2022
Append a file to a branch
touch file.name
git add -A
git commit -am "my update msg"
git push
How to shrink the .git folder
git gc --aggressive --prune # will perform garbage collection in your repository and prune old objects.
git repack -a -d --depth=250 --window=250 # It's better to use this command, because 'git gc --aggressive' is considered to be bad practice.
Delete all commit history
git checkout --orphan latest_branch # Checkout
git add -A # Add all the files to the 'current' branch
git commit -am "commit message" # Commit the changes
git branch -D main # Delete the branch 'main'
git branch -m main # Rename/move the 'current' branch to main
git push -f origin main # Finally, force update your repository
Delete/Remove a branch
git branch -d <branch-name>
Remove last Commit and Push from the Remote
git reset --soft HEAD~1
git push -f origin HEAD^:BRANCH_NAME
Now you are ready to push the same changes by a new commit.
Copy File from Another Branch
git restore --source master ./assets/css/src/style.less
Where master
is the name of the branch we want to copy from.
Hard Reset a Local Branch
BRANCH="master"
git stash
git fetch --all
git reset --hard FETCH_HEAD
git clean -df
git checkout "$BRANCH"
git pull --all
References
- Stack Overflow: How to delete all commit history in GitHub?
- Stack Overflow: How to shrink the .git folder
- Stack Overflow: How to clone all repos at once from GitHub?
- DevConnected: How To Undo Last Git Commit
- Stack Overflow: How can I remove a commit on GitHub?
- Stack Overflow: How do I copy a version of a single file from one Git branch to another?