GIT 上传、ssh设置、一些命令。

gitlab新建了这个项目。

按照官网的步骤上传代码

一:将本地代码上传到本地仓库

  1.进入项目文件夹 

  git init

  2.项目代码添加到本地git  

git add .

  3.提交到stage区域

git commit -m "这次同步的内容"

二:本地仓库连接远程gitlab地址

  1.连接gitlab的项目地址

git remote add origin https://gitlab.com/xxxxxx/xxxxxx.git

   2.上传本地代码

git push -u origin --all

  3.如果打了tag,上传tag

git push -u origin --tags

  

 ———————————————————设置———————————————————————————

1.安装之后设置用户名和邮箱

git config --global user.name "xxx"
git config --global user.email "xxx"

 

————————————————————ssh—————————————————————— 

[root@iZwz94d6ox6sdexe984lpuZ ~]# git config --global user.name "yindongzi"
[root@iZwz94d6ox6sdexe984lpuZ ~]# git config --global user.email "350343754@qq.com"
[root@iZwz94d6ox6sdexe984lpuZ ~]# cd /root/.ssh
[root@iZwz94d6ox6sdexe984lpuZ .ssh]# cat id_rsa.pub
ssh-rsa ……………………

  

生成密钥对:

ssh-keygen -t rsa -C "350343754@qq.com"

  

复制公钥的内容,粘贴到github。

 

然后在pc端登陆github

[root@iZwz94d6ox6sdexe984lpuZ .ssh]# ssh git@github.com
The authenticity of host 'github.com (13.250.177.223)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
RSA key fingerprint is MD5:16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,13.250.177.223' (RSA) to the list of known hosts.
PTY allocation request failed on channel 0
Hi ZhzhIn! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

  

——————————————命令————————

---git文件流:workspace-stage-master




git status 
#git checkout -xxx 撤销工作区的修改
git diff
#修改内容: 工作区修改

git add  (临时仓库-stage)
#git reset  撤销临时仓库的修改
git status

git commit(提交到仓库-master)
#git reset --hard HEAD^ 返回上一版本,^个数代表上几个存档
git push ()

git log
git push 推到对应的服务器(添加了ssh公钥的服务器)

—————————————rebase———————————  

合并status中的代码记录

git rebase  -i (对应代码版本的id)

  

git branch  dev#创建分支
git checkout dev#切换分支
git merge dev#把分支合入master ,当前处于master时才能合入其他分支

  _______________git remote_____________

git remote add originName xxxx.git 加载远程仓库的代码到本地
git branch  查看当前用户的branch
git branch -a 查看该项目的branch
git pull  把远程的master代码拉下来
# 处理冲突
git commit -a -m "fix"
git checkout master 切换到master分支 git merge remote/originName/HEAD 合并分支

git push 传到自己的远程仓库,github可以看到修改
git status 检查一下

  

————————常规操作——————————

git remote add other xxx.git
git fetch other master
git merge remote/other/master
git commit -a -m 

  

--------合并分支

合并dev分支代码到master

git checkout master
git merge dev
git status

  

------解决报错

在IDEA中进行分支切换时,出现如此错误,导致无法正常切换:error: The following untracked working tree files would be overwritten by checkout

通过错误提示可知,是由于一些untracked working tree files引起的问题。所以只要解决了这些untracked的文件就能解决这个问题。

    解决方式:

    打开SourceTree通过命令行,进入本地版本仓库目录下,直接执行

 

git clean -d -fx

  

 

------本地项目代码直推github

git init 
git add .
git commit -m "keke"

  

———— rebase后的代码记录

rebase master onto test

会将test的代码记录提交到master分支记录中(途中记录为master rebase后的代码记录),需要解决master和test的冲突

----------本地已经提交过代码了,rebase远程原master代码,不会对本地代码做任何变更

 

 

 

---------------- merge into current

 

 

 

posted @ 2018-06-06 09:55  头鹰在学习  阅读(6045)  评论(0编辑  收藏  举报