-
初始化仓库
git init
-
查看仓库日志
git log
-
查看仓库状态
git status
-
添加文件
git add filename
-
添加所有文件
git add -A . -
提交
git commit -m "<commit message>" -
添加远程仓库地址
git remote add origin <repository URL>
-
推送到远程仓库
git push -u origin master // 注释:远程分支为origin,默认的本地分支为master,-u是记住提交参数,下次可以直接使用git push 进行提交
-
拉取远程仓库
git pull origin master // 注释:同上
-
查看最近一次提交的更改
git diff HEAD //注释:HEAD为指针,diff的另一个重要用途是查看已经暂存文件内的更改。记住,staged文件是我们告诉git已准备好提交的文件。
-
取消暂存
git reset <filename> //注释:从暂存区移除指定文件
-
撤销
git checkout -- <filename> //注释:重新检出某个文件,恢复为最后一次commit的状态
-
创建分支
git branch <new_branch>
-
切换分支
git checkout <branch>
-
创建并切换分支
git checkout -b <new_branch> //注释:13、14两条命令的合并
-
移除文件
git rm '<filename>' //注释:此操作会同时从磁盘,暂存区移除指定文件 -
合并分支到master
git merge <branch>
-
移除分支
git branch -d <branch>
-
修改已存在仓库的URL
git remote rm origin git remote add origin [url]
-
设置提交的用户name和email
git config user.email personal@example.org git config user.name "whatf hobbyist" //注释:如果需要全局设置可以使用 --global -
相关链接
This repository was archived by the owner on Mar 25, 2025. It is now read-only.