git 简明教程

2022-12-24 0 362

origin

是远距库房的两个操作方式符

一般来说两个组成部分有关联两个远距库房,但也能有关联数个库房

remote

git remote 查阅远距库房简写(比如说 origin)

git remote -v 查阅origin对应的库房

git remote show origin查阅origin有关联远距库房的详细资料

remote能操作方式操作方式符

git remote rename origin new_origin重新命名

git remote remove origin/ git remote rm origin 删掉origin有关联远距库房有关的大部份追踪组成部分和实用性重要信息

git fork 拷贝远距库房

push

git push origin local_branch:remote_branch 将邻近地区组成部分发送到远距组成部分,假如该远距组成部分不存有则增建该远距组成部分

git push origin local_branch 略去了远距组成部分,预设将邻近地区组成部分发送到存有追踪亲密关系的远距组成部分(一般来说撞名),若该远距组成部分不存有则增建

git push origin :remoteBranch 略去了邻近地区组成部分的中文名称。将两个空的邻近地区组成部分发送到了远距组成部分上,原本的远距组成部分会被删去,相等于git push origin –delete remoteBranch

git push origin 将所处的邻近地区组成部分发送到已追踪的远距组成部分

git push 会采用git config中现阶段组成部分的预设远距库房别称(一般来说也是remote),适用于两个邻近地区组成部分只有两个远距组成部分,git是simple模式预设只发送现阶段组成部分

git push -u origin master 加-u是指定远距库房别称

HEAD

现阶段组成部分别称,push/pull时假如不指定具体分钟,则预设采用head指向邻近地区组成部分

git reset HEAD 恢复到初始状态

reset

git reset —hard commit_id 回退到某个版本,全部丢弃

git reset —soft commit_id 回退到某个版本,放回暂存区

git push -f 或者git push —force 将回退发送到远程

revert

消除某次提交修改,与reset区别:reset会彻底消除中间的多次commit_id。revert是用一次新的commit来回滚老的commit,老的commit记录会保存

checkout

git checkout . 恢复暂存区大部份文件到工作区

git checkout commit_id file 恢复某个commit的指定文件到工作区

git checkout file恢复暂存区的指定文件到工作区

fetch

Git pull = git fetch+git merge

branch

git branch new_branch_name 增建组成部分

git checkout branch_name 切换到该组成部分

git checkout -b new_branch_name = git branch+checkout

git branch -m branch_name new_branch_name重新命名

git branch -d branch_name 删掉组成部分

tag

git tag <tag-name> 现阶段commit打tag

git tag tag_name commit_id 给某个commit打tag

rebase

数个commit合并

git rebase -i [startpoint] [endpoint],endpoint假如不指定则预设是HEAD

-i表示交互:

pick:保留该commit(简写:p)

reword:保留该commit,但我需要修改该commit的注释(简写:r)

edit:保留该commit, 但我要停下来修改该提交(不仅仅修改注释)(简写:e)

squash:将该commit和前两个commit合并(简写:s)

fixup:将该commit和前两个commit合并,但我不要保留该提交的注释重要信息(简写:f)

exec:执行shell命令(简写:x) drop:我要丢弃该commit(简写:d)

将某一段commit粘贴到另两个组成部分上:cherry-pick也能实现

merge

git merge 预设是 -ff

—ff 快进,简单的移动操作方式符,没有增建commit id(假如顺着两个组成部分走下去能到达另两个组成部分的话,那么 Git 在合并两者时)

–no-ff 会增建两个commit id,与—ff区别在于假如 想reset,—ff会回退上次提交组成部分的上两个commit_id,而—no-ff会回到到master的上次最新版本,更

–squash 将dev上的提交合并为两个提交之后merge入master并产生两个新的提交

–no-squash

log

git log –pretty=oneline 显示友好

git reflog 查阅现阶段组成部分的最近几次提交

submodule

git clone –recursive 递归的方式克隆整个项目

git submodule add 添加子模块,url为submodule的repository url,path为添加到哪个路径。

git submodule init 初始化子模块

git submodule update 更新子模块

git submodule foreach git pull 拉取大部份子模块

patch

git format-patch -M master 现阶段组成部分大部份超前master的提交

git format-patch commitid1 commiti

stash

把现场暂时保存起来,等以后恢复现场后继续工作

git stash 暂存邻近地区文件变动 (Store changes temporarily)

git stash pop 删掉上一次暂存记录并将结果恢复到邻近地区代码(Remove and apply changes)

git stash apply 邻近地区暂存结果恢复到邻近地区代码并保留暂存记录

git stash list 查阅现有stash

git stash drop 移除stash

git stash show 查阅指定stash的diff

git stash branch <new feature> 从stash创建分支

cherry-pick

git cherry-pick commit_id 从commit_id取出来更新,合并到现阶段组成部分并提交,这个命令包含commit

.gitignore

忽略文件,用来记录那些无须纳入Git的管理,又不希望它们总出现在未追踪文件列表的文件

——————————

修改代码

git pull 先pull,假如有冲突解决

Git add

Git commit

Git push

从另两个组成部分摘取代码,合并到现阶段组成部分

git cherry-pick commit_id1 commit_id2 ..(具体看两个组成部分之间有多少个commit)

git push

撤销

git reset —hard commit_id 假如丢弃则–hard

git push -f origin rerank_debug_v1.0

拉取组成部分

git checkout -b rerank_v1.1

git push origin rerank_v1.1

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务