美文网首页
Git的使用

Git的使用

作者: LeepengX | 来源:发表于2017-08-07 19:16 被阅读0次

Git使用

git remote -v (verbose,啰嗦模式,展示详细信息):查看当前的远程主机配置,可以删除再添加新的。

git remote rm origin  :移除当前远程主机配置

git remote add origin *****.git :重新添加新的远程主机配置.

git log --pretty=oneline:一行行列出git的commit历史版本

下载完成后:git checkout SHA值 ,可以回滚代码到某个版本

下载的工程带有submodule

当使用git clone下来的工程中带有submodule时,初始的时候,submodule的内容并不会自动下载下来的,此时,只需执行如下命令:

git submodule update --init --recursive

即可将子模块内容下载下来后工程才不会缺少相应的文件。

git status 查看改动的仓库情况、状态

git stash ,git stash pop 临时存一下代码,便于回退。可以快速运行分支上的代码.命令输错,用Ctrl+C退出

进入ssh目录,打印自己的公钥:(填入git网站管理页面,指定读写权限)

$ cd ~/.ssh

$cat id_rsa.pub

http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013760174128707b935b0be6fc4fc6ace66c4f15618f8d000

删除分支:$ git push origin --delete lipeng

lipeng是分支名称(branchname)

首先要明确一点,对Git的操作是围绕3个大的步骤来展开的(其实几乎所有的SCM都是这样)1.    从git取数据(git clone)2.    改动代码3.    将改动传回git(git push)这3个步骤又涉及到两个repository,一个是remote repository,再远程服务器上,一个是local repository,再自己工作区上。其中1, 3两个步骤涉及到remote server/remote repository/remote branch,2涉及到local repository/local branch。git clone 会根据你指定的remote server/repository/branch,拷贝一个副本到你本地,再git push之前,你对所有文件的改动都是在你自己本地的local repository来做的,你的改动(local branch)和remote branch是独立(并行)的。Gitk显示的就是local repository。在clone完成之后,Git 会自动为你将此远程仓库命名为origin(origin只相当于一个别名,运行git remote –v或者查看.git/config可以看到origin的含义),并下载其中所有的数据,建立一个指向它的master 分支的指针,我们用(远程仓库名)/(分支名) 这样的形式表示远程分支,所以origin/master指向的是一个remote branch(从那个branch我们clone数据到本地),但你无法在本地更改其数据。同时,Git 会建立一个属于你自己的本地master 分支,它指向的是你刚刚从remote server传到你本地的副本。随着你不断的改动文件,git add, git commit,master的指向会自动移动,你也可以通过merge(fast forward)来移动master的指向。$git branch -a (to show all the branches git knows about)* masterremotes/origin/HEAD -> origin/masterremotes/origin/master$git branch -r (to show remote branches git knows about)origin/HEAD -> origin/masterorigin/master可以发现,master就是local branch,origin/master是remote branch(master is a branch in the local repository. remotes/origin/master is a branch named master on the remote named origin)$git diff origin/master master (show me the changes between the remote master branch and my master branch).需要注意的是,remotes/origin/master和origin/master的指向是相同的$git diff origin/master remotes/origin/mastergit push origin masterorigin指定了你要push到哪个remotemaster其实是一个“refspec”,正常的“refspec”的形式为”+:”,冒号前表示local branch的名字,冒号后表示remote repository下 branch的名字。注意,如果你省略了,git就认为你想push到remote repository下和local branch相同名字的branch。听起来有点拗口,再解释下,push是怎么个push法,就是把本地branch指向的commit push到remote repository下的branch,比如$git push origin master:master (在local repository中找到名字为master的branch,使用它去更新remote repository下名字为master的branch,如果remote repository下不存在名字是master的branch,那么新建一个)$git push origin master (省略了,等价于“git push origin master:master”)

$git push origin master:refs/for/mybranch (在local repository中找到名字为master的branch,用他去更新remote repository下面名字为mybranch的branch)

$git push origin HEAD:refs/for/mybranch (HEAD指向当前工作的branch,master不一定指向当前工作的branch,所以我觉得用HEAD还比master好些)

$git push origin :mybranch (再origin repository里面查找mybranch,删除它。用一个空的去更新它,就相当于删除了)

相关文章

  • Git常规使用

    Git怎么使用?使用 git commit 进行提交操作时,Git都做了什么? Git怎么使用? 下载、安装Git...

  • GIT和Github

    #Git的初识 ##Git 的使用 Git 使用初尝试 新建项目来操作 克隆已有项目来操作 Git 的使用 by ...

  • AD 使用 Git 的注意事项

    使用 Git 管理项目 Altium Designer 支持使用 Git/SVN 用以版本控制。如果使用 Git,...

  • git

    使用git add . 代替 git add *使用git add之后,怎样恢复?

  • git代理配置

    git http 使用 http proxy git http 使用 https proxy git http 使...

  • Git命令使用

    Git命令使用 前言在使用Git命令之前都使用可视化工具SourceTree操作git,现在需要Git Andro...

  • vscode操作git总让输入用户名密码

    clone使用git地址,不要使用https地址修改.git/config文件中的url = git@git.pl...

  • Git 的基本使用

    Git相关命令 安装Git 在Windows上安装Git (我是使用的Windows)在Windows上使用Git...

  • 前端学习路线(2)——Git使用、DIV+CSS布局

    Git使用、DIV+CSS布局 1. Git使用 链接:git下载链接:git for windows(下载速度可...

  • Git 18使用别名

    GIt 使用别名 ======== 在Git中可以将经常使用的命令以别名缩写的方式简化使用 命令 git conf...

网友评论

      本文标题:Git的使用

      本文链接:https://www.haomeiwen.com/subject/gugalxtx.html