首页 > IT职业 > IT生活 > Git常用命令总结及一些问题思考
感谢廖雪峰大神分享的Git课程
掌握以下命令,基本上日常够用
git init
git add file
git commit -m "commint describtion"
git reset /git reset HEAD file
git checkout -- file
git rm file
相当于git rm后git add
git reset git checkout --file
git cat file
git diff
git log
git reflog
git reset --hard commit-id
或 git reset --hard HEAD-id相当于指定当前HEAD到指定版本
git checkout -b
git checkout
git branch
详细信息 git branch -v
git merge
git merge --no-ff -m "" 此信息会在远程显示
git branch -d
git stash
git list
git stash pop
git add .
ssh -T git@github.com
git remote add origin git@github.com:路径/版本库.git
git clone git@server:path/repo.git
git checkout -b branch origin/branch
git pull
git push -u origin master
git push
git remote show origingit remote -v
git diff
git fetch --all git reset --hard origin/master git pull
git remote update
git fetch origin branch-name
git branch --set-upstream-to
git clone -b
手动解决冲突之后 冲突文件-->git->Resolve Conflicts
commit 后无提交说明遇到的问题:Vim: Caught deadly signal SEGV,无法继续操作git
?只能重启git窗口?
退出log界面:q键退出
删除部分log?
git reset --hard commit-id: HEAD指向commit-id版本,log只显示当前HEAD版本 ,回退全部后仍可显示全部log
删除全部log?待研究
查看帮助:git --help ;指定命令帮助 git log -help;
git reset --hard HEAD-id:回退到指定HEAD版本,id可通过git reflog查看
git reset HEAD^
无--hard时:Unstaged changes after reset: M
有--hard时:
完整命令: git reset --hard HEAD^HEAD is now at
结果HEAD都指向指定版本
未commit的:
checkout --
已commit的:
reset后checkout也无法撤销,想撤销只能reset --hard commit-id或reset --hard HEAD回退到提交删除之前,无法回退指定文件
添加远程仓库时提示:fatal: remote origin already exists.
vi
.git/config删除remote “origin”
ESC后 shift+zz保存 退出
版本库内文件,同一路径下的多个分支共享,分支提交,合并到主线
远程库默认名称根据我们初次连接远程库时创建的为准
git pull 提示
there is no tracking information for the current branch说明本地分支和远程分支的连接关系没有创建
git pull提示error: The following untracked working tree files would be overwritten by merge:.....
Please move or remove them before you can merge.
Aborting
git clean -d -fx ""
其中
x -----删除忽略文件已经对git来说不识别的文件
d -----删除未被添加到git的路径中的文件
f -----强制运行
进入指定目录后
若无仓库时初始化仓库
关联远程仓库:git remote add origin git@server-name:path/
查看远程仓库信息:
git remote -v
git remote show origin
git remote update
git pull
以上三个命令提示:
GitLab: The project you were looking for could not be found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
checkout -b / 时:提示:fatal: 'origin/branch' is not a commit and a branch 'branch' cannot be created from it
checkout / 时提示:error: pathspec 'branch' did not match any file(s) known to git.
error: pathspec 'origin/branch' did not match any file(s) known to git.
此时只能克隆 git clone git@server-name:path/ 获取仓库再操作
待研究验证
已建立本地仓库与远程仓库对应连接,默认为master分支,需要切换到已clone的仓库代码路径,继续操作
git remote show origin 提示 tracked git remote update git pull 无最新提交提示already up-to-dategit fetch
以上命令均可正常操作
建立并切换到与远程库对应本地分支 git checkout -b branch origin/branch,
变更已clone过的master分支代码为指定分支代码
git checkout master 切换到master分支,代码重下载
分支切换过程工作区代码会跟随分支变动
git status 查看仓库状态,未修改工作区情况下仓库状态不变 working tree clean
追踪远程库git fetch origin branch
拉取最新提交git pull origin branch指定分支或git pull默认当前对应分支
建立连接git branch --set-upstream-to
问题:遇到过 git pull 及git remote update 不拉取提示new 且未追踪,待复现
切换分支之前需commit工作区到本地分支仓库,提交之后再切换分支,仓库代码将会有所区别
git stash临时保存工作区后,需记住stash id,再切换分支操作,切回远分支后通过git
stash pop或stash apply 恢复原工作区
本地修改分支:用于本地修改
远程同步分支:用于pull及push;本地修改分支合并到该分支,再push
切换分支前提交或临时保存本地修改分支修改内容到本地仓库,以便切回该分支继续修改
查看远程仓库信息 git remote show origin
追踪最新提交git fetch origin branch
拉取最新提交 git pull
关联本地仓库到远程仓库,
clone远程分支,
git fetch追踪,
git pull拉取
git push
提示:fatal: The upstream branch of your current branch does not matchthe name of your current branch. To push to the upstream branchon the remote, use
`git push origin HEAD:`
`To push to the branch of the same name on the remote, use
git push origin`
git stash保存本地工作区
git checkout 切换到远程分支
git pull拉取远程提交
git checkout 切回本地
git merge --no-ff -m "" 远程分支合并到本地,解决冲突
git checkout
git merge --no-ff -m "" 本地分支合并到远程
git push origin HEAD:或git push
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1795/viewspace-2812742/ ,如需转载,请注明出处,否则将追究法律责任。