- git add file
- git commit -m “comments”
- git diff :查看工作目录和暂存区区别
git diff HEAD:查看工作目录和本地仓库区别
git diff –cached:查看暂存区和本地仓库区别 - git log
git log –graph:分支合并图 - 版本回退: git reset –hard commit_id
回到上一个版本:git reset –hard HEAD^ - 重返未来:git reflog 查看命令历史确定版本号,然后再 git reset –hard commit_id.
- 工作区 — git add —> 暂存区(stage/index) — git commit —> 本地仓库
- 撤销修改
- 撤销工作区修改,还未添加到暂存区:git checkout – file(git checkout – file 是用暂存区的文件替换工作区文件,所以当误删文件时,也可以通过其恢复)
- 已经添加到暂存区:git reset HEAD file + git checkout – file
- 已经添加到本地仓库:版本回退
- git rm file:删除文件
- 关联远程仓库:git remote add origin git@server-name:path/repo-name.git
推送:git push <远程主机名> <本地分支名>:<远程分支名> - 分支
查看分支:git branch
创建分支:git branch
切换分支:git checkout
创建+切换分支:git checkout -b
合并某分支到当前分支:git merge
Fast forward 模式合并不会显示历史分支,禁用此模式:git merge –no-ff -m “merge with no-ff”
删除分支:git branch -d
远程分支的创建不能通过git branch 进行,而是在git push的时候默认执行
团队合作分支模式 - git stash:保存工作现场
git stash list
git stash apply
git stash drop
git stash pop - git remote:查看远程仓库
从本地推送分支,使用git push origin branch-name,如果推送失败,先用git pull抓取远程的新提交
在本地创建和远程分支对应的分支,使用git checkout -b branch-name origin/branch-name,本地和远程分支的名称最好一致
建立本地分支和远程分支的关联,使用git branch –set-upstream branch-name origin/branch-name
从远程抓取分支,使用git pull,如果有冲突,要先处理冲突 - tag
- 新建标签: git tag ,commit id 默认为HEAD
- 指定标签信息:git tag -a -m “blablabla…”
- 查看所有标签:git tag
- 推送本地标签到远程:git push origin
- 推送搜有标签:git push origin –tags
- 删除本地标签:git tag -d
- 删除远程标签:git push origin :refs/tags/
- git pull <远程主机名> <远程分支>:<本地分支>
- git push
git push -u origin <local-branch>
: set the upstream association for any future push/pull attempts automatically.
- git branch
git branch --set-upstream <remote-branch>
: sets the default remote branch for the current local branch.
Any future git pull command (with the current local branch checked-out),will attempt to bring in commits from the into the current local branch.
Git Notes
最新推荐文章于 2024-08-04 14:57:52 发布