原理图:
三个对象构成多种变化
git [common commands]
这些是在各种情况下使用的常见Git命令
start a working area
- clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one
work on the current change
- add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
examine the history and state
- bisect Use binary search to find the commit that introduced a bug
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status
grow, mark and tweak your common history
- branch List, create, or delete branches
checkout Switch branches or restore working tree files
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
merge Join two or more development histories together
rebase Reapply commits on top of another base tip
tag Create, list, delete or verify a tag object signed with GPG
collaborate
- fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects
git 的常用命令
和远程仓库有关
要查看远程库
git remote
要查看远程库de更详细的信息:
git remote -v
克隆远程仓库,【默认情况下只能看到本地的master分支】
git clone git@github.com:XXX/XXX.git
创建远程origin的dev分支到本地,【本地和远程分支的名称最好一致】
git checkout -b dev origin/dev
推送本地分支
git push origin dev
推送失败,败抓取远程的新提交;
git pull
成功拉取但是有冲突,需要手动解决【去文件里面修改后】,解决后,提交【git commit -m “fix conflict”】,再push【git push origin dev】:
git pull如果失败,则设置dev和origin/dev的链接
指定本地dev分支与远程origin/dev分支的链接
git branch --set-upstream-to=origin/dev dev
分支有关
查看本地分支
git branch
创建本地分支
git branch branchname
创建并切换到本地分支
git checkout -b branchname
git switch -c branchname
删除本地分支
git branch -d branchname
强行删除本地分支【在分支未合并的状态下】
git branch -D branchname
删除远程分支
git push origin --delete [branchname]
撤销和删除操作
撤销工作区的修改
git checkout --filename
撤销添加到stage
git reset HEAD filename
回退版本
git reset --hard HEAD^【回退上个版本】
git reset --hard commit_id【根据commit回退版本】
删除本地仓库文件
git rm filename && git commit -m ‘message’