您的位置:首页 > 其它

关于git的简单使用

2017-07-06 15:28 211 查看
1.github上注册个账号。

2.本地安装了git之后,在项目文件夹(选文件夹右键点击git bash)下:

3.$ ssh-keygen -t rsa -C
"youremail@example.com"   
*****创建自己的gitSSH Key公钥

4.将公钥加进自己账户setting中的ssh key

5.初始化本地仓库:git init

6.$ git remote add origin
git@github.com:YourGithubName/demo.git 
*****把一个已有的本地仓库与之关联。
7.添加内容进暂存区:git add filename 或者git add *(全部拖进去)
8.提交:git commit -m “修改的说明”

9.$ git push -u origin master 第一次要加-u,因为仓库是空的
10.$ git push origin master 第二次开始直接用这句就可以了 查看该仓库状态:git
status


查看修改内容:git diff

$ git reset --hard HEAD^ 上一个版本

$ git reset --hard 3628164

   
HEAD指向的版本就是当前版本,因此,Git允许我们在版本的历史之间穿梭,使用命令git reset --hard
commit_id。

    穿梭前,用git
log可以查看提交历史,以便确定要回退到哪个版本。

    要重返未来,用git
reflog查看命令历史,以便确定要回到未来的哪个版本。

遇到下面情况时

******

error: failed to push some refs to
'git@github.com:AlanKnightly/sum.git'

hint: Updates were rejected because the remote contains work that
you do

hint: not have locally. This is usually caused by another
repository pushing

hint: to the same ref. You may want to first integrate the remote
changes

hint: (e.g., 'git pull ...') before pushing again.

hint: See the 'Note about fast-forwards' in 'git push --help' for
details.

******

git branch --set-upstream-to=origin/ master实际上就是:

git branch --set-upstream-to=origin/master master

git pull
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: