Created
September 23, 2017 00:30
-
-
Save ygweric/efa33e4141771f42a0fb444c08762005 to your computer and use it in GitHub Desktop.
Git commands list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GIT COMMAND | |
//edit the last commit | |
git commit --amend -m "New commit message" | |
#Remove information on branches that were deleted on origin | |
git fetch --prune | |
# to create a new branch and switch to it in one step | |
$ git checkout -b <branch-name> | |
//checkout a tag as branch | |
git checkout -b appstore v3.0.0_1 | |
$ git merge hotfix 合并某个branch | |
#checkou a commit as branch | |
git checkout -b newbranchname 0d1d7fc32 | |
//push a branch | |
git push -u origin mybranch | |
#diff file has added | |
$ git diff --cached | |
//revert an published commit | |
git revert dd61ab32 | |
//check an old commit as a commit | |
git co -b nt2 128a1a108e7affc | |
//remove local branch | |
git branch -D the_local_branch | |
//push a branch | |
git push origin newbranch | |
//rename a local Git branch? | |
git branch -m <oldname> <newname> | |
//If you want to rename the current branch, you can simply do: | |
git branch -m <newname> | |
//add tag | |
git tag -a v3.4.0 -m "app store 3.4.0." | |
#rename a tag | |
git tag new old | |
//show all tags | |
git tag | |
//git delete a tag | |
git tag -d tag1 | |
//show tag info | |
git show v1.0.0 | |
//save stash with name | |
$ git stash save "show reply text on my reply view" | |
//delete one stash | |
git stash drop stash@{0} | |
//show the a list of special commit | |
git diff-tree --no-commit-id --name-only -r 73f6f7cd898241c2d661c76b253c32d11be3b8a5 | |
#rename a remote | |
git remote rename origin destination | |
# Change remote name from 'origin' to 'destination' | |
//undo merge | |
git reset --hard HEAD^ | |
git reset --hard HEAD~5 | |
# get all git command history | |
git reflog --date=local | |
//get branch diff | |
git diff master..branch | |
git diff --name-status master..branch | |
//show all conflicted file after merge branch | |
git diff --name-only --diff-filter=U | |
//show diff which was "git add" | |
git diff --cached | |
//Fetching a remote | |
git pull -u originmaster master | |
//download submodule recursive | |
git submodule update --init --recursive | |
//list special tag list | |
$ git tag -l v1.4.2.* | |
//show tag info | |
$ git show v4.0.0 | |
//show commit info | |
$ git show 1894ce8b333e9ed8da | |
# update fork repository: | |
1. git fetch upstream | |
2. git merge upstream/master | |
# add remote | |
git remote add upstream https://github.com/xxx.git | |
#check remote branch | |
git fetch | |
git checkout test | |
# modify last commit | |
git reset --soft HEAD^ | |
git reset HEAD path/to/unwanted_file | |
git commit -c ORIG_HEAD | |
# Ignore some file temporary | |
git update-index --assume-unchanged [file] | |
git update-index --no-assume-unchanged [file] | |
~/.ssh/config | |
Host company | |
HostName eric@company.com | |
IdentityFile ~/.ssh/id_rsa_company | |
Host github | |
HostName eric@gmail.com | |
IdentityFile ~/.ssh/id_rsa_github | |
Changing a commit message | |
git rebase -i HEAD~3 | |
#Reset all local changed | |
git reset --hard origin/development | |
git checkout --theirs company/xxxx | |
rename: | |
1. Rename your local branch | |
If you are on the branch you want to rename: | |
git branch -m new-name | |
If you are on a different branch: | |
git branch -m old-name new-name | |
2. Delete the old-name remote branch and push the new-name local branch | |
git push origin :old-name new-name | |
3. Reset the upstream branch for the new-name local branch | |
git push origin -u new-name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment