From 1f93626bf25d35ad7b9697bd595122a35fda7461 Mon Sep 17 00:00:00 2001 From: Yu Liang Date: Tue, 26 Nov 2024 19:30:37 -0500 Subject: [PATCH] (fix) Fix formatting on the last commit. --- content/post/Useful_Git_Commands.md | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/content/post/Useful_Git_Commands.md b/content/post/Useful_Git_Commands.md index 4ca2509..433b15f 100755 --- a/content/post/Useful_Git_Commands.md +++ b/content/post/Useful_Git_Commands.md @@ -8,57 +8,89 @@ tags: --- `git log`: Output git commits history. + `git log --graph `: Output git commits history in graph mode. + `git add `: Add files to the git tracking and committing system. + `git status`: Check Git Status + `.gitignore`: Input files that will be ignored by Git. **But if files are already inside the git tracking system, it won't delete it from git. We have to use `git rm filename` to remove it.** + `git diff`: check file changed that is not staged. + `gif diff --staged`: check file changed that is staged. + `git add --all`: add all changes to the git tracking. + `git commit`: Submit changes to git. + `git commit -a`: Submit changes with all changes. Still need to call `git add all` + `git commit --amend`: Revert and re-commit the last git submission. + `git rm –cached < filename >`: Delete file from git submission. But does not delete local file. + `git reset – < file >`: change the current HEAD pointers to previous commits. Depends on --hard or --soft, will or will not change the local file. + `git checkout -- `: Change to local file to specific commits. Does not move HEAD pointer in Git. + `git remote -v`: Output remote server and its URL. + `git remote add `: + `git remote rm `: + `git fetch `: Receive the remote server's update. Will put into /branch. + `git pull`: Automatically fetch and then merge into current. + `git push `: push to the remote server. + `git push --tags`: push to the remote server with tags information. + `git tag -d `: Delete tags information + `git checkout master`: Checkout the master branch. + `git merge `: Git will decide which branch will become its ancestor. If we have conflicts in merge: `git mergetool`: GUI tool used to fix conflicts. Then use `git merge` to merge. + `git branch`: Output all branches information. It is OK to repeatedly merge other branches to one branch. For example, we can repeatedly merge *test_branch* to *master* branch. `git push origin --delete ` Delete remote branch. + `git rebase -i HEAD~3` Change the last three commits, very useful tool to re-generate commits history. ### Added after March, 2023: `git worktree add `: Checkout another branch in a separate folder. The current branch folder and the new checkout folder will co-exist, and sync with the updates (for different branches). + `git worktree list`: List all currently checkout work trees. + `git worktree remove `: Remove the work tree from the file system. ### Signing related: `gpg --list-keys` && `git config --global user.signingkey `: Check you gpg key and import it to your git. Make sure the gpg key email matches your git registered email. + `git config --global commit.gpgsign true`: Auto sign by default. ### Just interesting new command: `git push --force-with-lease`: Force push if the reference tree is not changed by others. Safer force push. + `git diff --word-diff`: Word diff instead of line diff. + `git config --global branch.sort -committerdate`: Sort branch based on commit date instead of alphabetic. + `git maintenance start`: On your most commonly used commit, auto run git maintenance jobs such as prefetching periodically. + `git clone --filter=blob:none`: Download the git commit tree and the latest blob, but skipped the history blob at the time. Git will fetch for blob if you ask for history commit data. If you are working with super large monorepo, you can use `scalar` command, an alternative `git` command that wraps up some `git` commands optimized for large repos. \ No newline at end of file