参照廖雪峰的git教程。https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
1.安装
sudo apt-get install git
2.登录
git config --global user.name "Your Name" LightningApple
git config --global user.email "email@example.com" 1000@qq.com(只要是自己的邮箱就可以了)
3.创立仓库
cd “仓库目录”
git init #会生成.git文件
4.提交代码
git add readme.txt
git add ...
git commit -m "message"
5.查看更改记录或当前状态
#代码最后用utf-8格式编码
git status #查询仓库当前的状态
git diff readme.txt #查看文件具体修改了什么内容
git log #查看历史记录
git log --pretty=oneline #单行历史记录,没有时间
6.版本回退
git reset --hard HEAD^
#HEAD 当前版本
#HEAD^ 上一个版本
#HEAD^^ 上上个版本
#HEAD~100 往上100个版本
git reset --hard commit_id
git reflog #记录用户的每一次命令
git diff HEAD -- file #查看工作区和版本库里面最新版本的区别
7. 文件撤销
git checkout -- file #让文件回到最近一次git commit或git add时的状态
git reset HEAD file #把暂存区的修改回退到工作区
8. 版本区的文件删除
git rm file
git commit -m ""
9.提交到github
…or create a new repository on the command line
echo "# test" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:LightningApple/cs231-ztt.git
#git remote rm origin 删除origin
git push -u origin master
10. git add . #提交修改或新增的全部文件