From 517ce0ea59e6f983702b6a66c6c47b6842e94159 Mon Sep 17 00:00:00 2001 From: thangtd-0050 <49503829+thangtd-0050@users.noreply.github.com> Date: Fri, 2 Oct 2020 22:49:53 +0700 Subject: [PATCH] Add some useful git commands Add some useful git commands, about `git reset --hard`, `git rm --cached`, `git remote rm`, `git log --oneline`, `git commit --amend`, `git show`, `git diff` ... --- tools/git.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/git.sh b/tools/git.sh index c2f3da5..f67bfc7 100644 --- a/tools/git.sh +++ b/tools/git.sh @@ -4,7 +4,9 @@ git clone
# creates a git repo from given address (get the address fro git add file.txt # adds(stages) file.txt to the git git add * # adds(stages) all new modifications, deletions, creations to the git git reset file.txt # Removes file.txt from the stage +git reset --hard # Throws away all your uncommitted changes, hard reset files to HEAD git rm file.txt # removes file.txt both from git and file system +git rm --cached file.txt # only removes file.txt both from git index git status # shows the modifications and stuff that are not staged yet git branch # shows all the branches (current branch is shown with a star) @@ -19,11 +21,19 @@ git cherry-pick # merge the specified commit git remote # shows the remotes git remote -v # shows the remote for pull and push git remote add my-remote
# creates a remote (get the address from your git-server) +git remote rm my-remote # Remove a remote git log # shows the log of commits +git log --oneline # shows the log of commits, each commit in a single line git commit -m "msg" # commit changes with a msg +git commit --amend # combine staged changes with the previous commit, or edit the previous commit message without changing its snapshot +git commit --amend --no-edit # amends a commit without changing its commit message git push my-remote my-branch # pushes the commits to the my-remote in my-branch (does not push the tags) +git show # shows one or more objects (blobs, trees, tags and commits). +git diff # show changes between commits, commit and working tree +git diff --color # show colored diff + git tag # shows all the tags git tag -a v1.0 -m "msg" # creates an annotated tag git show v1.0 # shows the description of version-1.0 tag