new folder
$ mkdir peyzhang -git
$ cd peyzhang -git
Create warehouse
$ git init
Initialized empty Git repository in user/peyzhang -git/.git/
Add and submit files
Git needs to add files to add, commit a total of two steps
$ git add file1.txt
$ git add file2.txt file3.txt
$ git commit -m "add 3 files."
View the commit log git log ( git log --pretty=oneline Simplified version)
$ git log
commit b438621bd89c5c2cfe8db411407cb5634b69573d (HEAD -> master)
Author: peyzhang <15385136323@163.com>
Date: Tue Sep 20 14:04:54 2022 +0800
add my first git file
revert to previous version
The original is HEAD^
, the last version is , of course, it is easier to HEAD ^^
write the previous 100 versions than count, so it is written . Hard can be followed by the version number100个^
HEAD~100
$ git reset --hard HEAD^
# hard 后面可以接版本号 hard b4386 (可以不用写全)
HEAD is now at b438621 add my first git file
work area
Check status - what was changed and what was committed
$ git status
Undo changes
$ git checkout -- readme.txt
Delete Files
$ git rm test.txt
$ git commit
Remote Connection
# 1.设置用户名
$ git config --global user.name ‘peyzhang’
# 2.设置用户名邮箱
$ git config --global user.email ‘***’
# 3.查看设置
$ git config --list
# 4.然后继续输入命令:修改后面的邮箱即可,创建ssh key
$ ssh-keygen -t rsa -C "***@***.com"
# 5.链接远程
$ git remote add origin [email protected]:zpp6907/gittest.git
remote clone
# clone
git clone [email protected]:zpp6907/gittest.git
# 拉代码
git pull origin master
Create and merge branches
# 查看当前分支
git branch
# 切换并创建分支 git checkout ***
git checkout -b ***
# 合并分支(需先切换到原来的分支)
git merge dev
# 切换分支用此方法也可以
git switch -c dev
Reference https://www.liaoxuefeng.com/wiki/896043488029600/897271968352576