$ git init
$ git init [project-name]
$ git clone [url]
Git 的设置文件为.gitconfig,它可以在用户主目录下(全局配置),也可以在项目目录下(项目配置)。
$ git config [--global] user.name "[name]"
$ git config [--global] user.email "[email address]"
$ vim ~/.gitconfig
$ git config --list
$ cat ~/.gitconfig
$ git add [file1] [file2] ...
$ git add [dir]
$ git add .
$ git rm 1.txt 2.txt
error: the following files have changes staged in the index:
1.txt
2.txt
(use --cached to keep the file, or -f to force removal)
$ git rm -fr 1.txt
$ git rm --cached [file]
$ git rm --cached 1.txt 2.txt
rm ‘1.txt‘
rm ‘2.txt‘
$ git mv [file-original] [file-renamed]
$ git commit -m [message]
$ git commit [file1] [file2] ... -m [message]
$ git commit -a
$ git commit -v
$ git commit --amend -m [message]
$ git branch
*表示当前分支
$ git branch -r
$ git branch -a
$ git branch [branch-name]
$ git checkout -b [branch]
$ git log
commit 2cb44e585aab4d1b2370a3e42dc6d4070fe217dc (HEAD -> DevOps_RC, origin/master, master, DevOps_Release, DevOps_Dev)
Author: zhangsan <zhangsan@263.com>
Date: Sat Jul 10 11:03:12 2021 +0800
修改了ReadMe.md文件,添加了一行说明
commit 89d1d5b198a77deb9096e11b02aec7187221f384
Author: zhangsan <zhangsan@263.com>
Date: Sat Jul 10 10:59:09 2021 +0800
:...skipping...
commit 2cb44e585aab4d1b2370a3e42dc6d4070fe217dc (HEAD -> DevOps_RC, origin/master, master, DevOps_Release, DevOps_Dev)
Author: zhangsan <zhangsan@263.com>
Date: Sat Jul 10 11:03:12 2021 +0800
修改了ReadMe.md文件,添加了一行说明
commit 89d1d5b198a77deb9096e11b02aec7187221f384
Author: zhangsan <zhangsan@263.com>
Date: Sat Jul 10 10:59:09 2021 +0800
添加User文件夹
commit b54962a30b090f02a39fc3c6185750cf07b068ea
Author: zhangsan <zhangsan@263.com>
Date: Sat Jul 10 10:58:30 2021 +0800
添加忽略文件
commit e76012d77857841d344ac04893a158e75e8088fc
Author: zhangsan <zhangsan@263.com>
Date: Sat Jul 10 10:56:46 2021 +0800
添加Readme.md文件
$ git branch [branch] [commit]
$ git branch DevOps_V0.3FixBug 89d1d5b198a77deb9096e11b02aec7187221f384
$ git branch --track [branch] [remote-branch]
$ git branch --track DevOps_RC1 DevOps_RC
$ git checkout [branch-name]
$ git checkout DevOps_RC1
$ git pull
$ git branch --set-upstream [branch] [remote-branch]
$ git merge [branch]
$ git cherry-pick [commit]
$ git branch -d [branch-name]
$ git push origin --delete
$ git branch -dr
$ git tag
$ git tag [tag]
$ git tag [tag] [commit]
$ git show [tag]
$ git push [remote] [tag]
$ git push [remote] --tags
$ git checkout -b [branch] [tag]
$ git status
$ git log
$ git log --stat
$ git log --follow [file]
$ git whatchanged [file]
$ git log -p [file]
$ git blame [file]
$ git diff
$ git diff --cached []
$ git diff HEAD
$ git diff [first-branch]...[second-branch]
$ git show [commit]
$ git show --name-only [commit]
$ git show [commit]:[filename]
$ git reflog
$ git fetch [remote]
$ git remote -v
$ git remote show [remote]
$ git remote add [shortname] [url]
$ git pull [remote] [branch]
$ git push [remote] [branch]
$ git push [remote] --force
$ git push [remote] --all
$ git checkout [file]
$ git checkout [commit] [file]
$ git checkout .
$ git reset [file]
$ git reset --hard
$ git reset [commit]
$ git reset --hard [commit]
$ git reset --keep [commit]
$ git revert [commit]
======================================================================
创作不易,本人热衷开源共享 Git常用命令超级详细(全网最详细)
======================================================================
转载请附上链接:
https://www.cnblogs.com/cndevops/p/14993331.html
原文:https://www.cnblogs.com/cndevops/p/14993331.html