1、git的简单命令
git init: 初始化git,将当前文件夹用git管理起来
mashiqiandeMBP:c mashiqian$ git init Initialized empty Git repository in /Users/mashiqian/Desktop/c/.git/
git status:查看git状态
mashiqiandeMBP:c mashiqian$ git status On branch master No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) login.py nothing added to commit but untracked files present (use "git add" to track)
git add 文件名:将指定文件添加到暂存区
git add . : 将所有文件添加到暂存区
mashiqiandeMBP:c mashiqian$ git add login.py
这时再次查看git状态
mashiqiandeMBP:c mashiqian$ git status On branch master No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: login.py
git commit -m '注释':将文件提交到本地仓库
mashiqiandeMBP:c mashiqian$ git commit -m '立项' [master (root-commit) 3448e89] 立项 Committer: 麻世骞 <mashiqian@mashiqiandeMBP.lan> Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly. Run the following command and follow the instructions in your editor to edit your configuration file: git config --global --edit After doing this, you may fix the identity used for this commit with: git commit --amend --reset-author 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 login.py
此时再次查看git状态
mashiqiandeMBP:c mashiqian$ git status
On branch master
nothing to commit, working tree clean
git log:查看日志
git reflog:查看详细日志
mashiqiandeMBP:c mashiqian$ git log commit 3448e89964aae9f17442d486ec634e96df6edda8 (HEAD -> master) Author: 麻世骞 <mashiqian@mashiqiandeMBP.lan> Date: Thu Sep 19 15:06:52 2019 +0800 立项
git config user.name '添加内容':添加作者名字
git config user.email '邮箱':添加作者邮箱
mashiqiandeMBP:c mashiqian$ git config user.name '麻世骞' mashiqiandeMBP:c mashiqian$ git config user.email 'aaa@163.com'
此时再查看日志
mashiqiandeMBP:c mashiqian$ git log commit 9284b04c236ac825cc8c4f493098796ef61bd281 (HEAD -> master) Author: 麻世骞 <aaa@163.com> Date: Thu Sep 19 15:17:31 2019 +0800 添加了一个变量
git reset HEAD^--文件名:在暂存区的文件会推倒指定版本
git diff HEAD -- 文件名 :比较工作区修改前后的不同
git diff HEAD HEAD^ -- 文件名:比较心就版本的不同
git rm 文件名:提交删除
git checkout :撤销修改
git push:推送到远程服务器
git pull:从远程服务器下载最新代码
git tag -a 标签名 -m ‘标签描述’:在本地仓库添加标签
git push origin 标签名:向远方仓库推送标签
git checkout -b 分支名:创建分支
git checkout 分支名:切换分支
git push origin 分支名:向远方仓库推送分支