Git常用操作
Git学习教程
自学git时所使用的git教程,如果是初学 Git,那么学完第7章就差不多了。
Git操作三板斧
git status
用于查看当前分支的基本信息,如“处于什么分支”“有哪些文件被修改”“有哪些文件未被追踪”等。
git add
1 2
| git add . git add <file>
|
这条命令用于把修改存入暂存区,如果只想暂存特定的几个文件,就写对应的文件名。
git commit
这条命令用于提交暂存区的修改,引号内可以简略写上本次提交所做的修改内容。
安装与一次性配置
1 2 3
| git --version git config --global user.name "Your Name" git config --global user.email "you@example.com"
|
分支与合并
1 2 3 4 5 6 7 8
| git branch git branch <name> git switch -c <name> git switch <name> git merge <branch> git rebase <branch> git branch -d <name> git branch -D <name>
|
远程协同
1 2 3 4 5 6 7
| git remote -v git remote add origin <url> git push -u origin main git push git pull git fetch git push origin --delete <branch>
|
撤销与回退
1 2 3 4 5 6
| git restore <file> git restore --staged <file> git commit --amend git reset --hard <commit> git reset --soft/--mixed <commit> git revert <commit>
|