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