git 代碼上傳到服務器

首次上傳代碼到git服務器,感受本身踩了全部的能踩的坑html

**1**.將本地的SSH_Key祕鑰給後臺,容許你的訪問權限
**2.**在你要上傳代碼工程的根目錄(eg:若是要上傳的工程師Test,那麼就在Test裏面的一層,不然上傳是一個文件夾)下,打開git Bash。接下來就是提交代碼的一套了

   a_)  git init,建倉操做,

   b_) git add.添加全部文件,

問題:git add.時出現
warning: LF will be replaced by CRLF in test.html.The file will have its original line endings in your working directory.

執行git config core.autocrlf false命令以後,再次執行add命令就可成功。

   c_) git commit -m "first commit"

   d_) git remote add origin git @ url 地址

   e_) git push -u origin master

這時可能會出現的問題:Updates were rejected because the tip of your current branch is behind
有以下幾種解決方法:
 1.使用強制push的方法:
 $ git push -u origin master -f
這樣會使遠程修改丟失,通常是不可取的,尤爲是多人協做開發的時候。
2.push前先將遠程repository修改pull下來
$ git pull origin master
(這個時候還會出現一個問題  fatal: refusing to merge unrelated histories,
解決方法: git pull origin master --allow-unrelated-historie  後面沒有說明(相似於 git commit -m "msg"的msg)就會進入vim模式,而後直接輸入一個說明回車,而後在輸入:wp就會跳出來了
)
$ git push -u origin master
3.若不想merge遠程和本地修改,能夠先建立新的分支:
$ git branch [name]
而後push
$ git push -u origin [name]
(中間嘗試了提交到新的分支上,而後在和master分支合併可是並無合併成功,直接切換分支下載代碼也出現了git Please move or remove them before you can checkout 的報錯,而後去清楚多餘的不用git管理的文件https://blog.csdn.net/chinacmt/article/details/52221733,然並卵,應該和原來服務器中建項目時,添加的一些配置有衝突)
分支管理:

一、建立分支: git branch
 new_branch

二、查看分支:git branch

三、刪除分支:git branch
 -d new_branch

四、切換分支:git checkout
 new_branch

五、建立分支並切換分支: git checkout
 -b new_branch便可在本地新建分支,並使用該分支track遠程分支

六、提交併推送分支:

git
 add .

git
 commit -m "xxx"

git
 push -u origin new_branch

七、刪除遠程分支:git
 push origin --delete new_branch

八、合併分支: git merge
 new_branch

九、將本地更新上傳到遠程分支上:

例如本地新建或是更新了內容newfile.c文件, 

首先git add newfile.c,

而後git commit -m "add new file",

緊接着git push 本地分支名 遠程分支名便可將本地分支更新到遠程分支。

10.獲取遠程分支

git fetch 從遠程獲取其餘用戶push上來的新分支

git remote -v  便可查看遠程全部的版本信息
又由於原來的代碼在svn上,致使後來上傳的代碼沒辦法在AS中直接鏈接git,
因此要斷開svn的鏈接,嘗試了註冊表的d方法(https://blog.csdn.net/scry5566/article/details/51671919),
可是並無論用,而後直接來了一個簡單粗暴的方法(https://jingyan.baidu.com/article/60ccbceb60cb2c64cbb19743.html)
直接把原來文件中隱藏的.svn文件夾刪除、將.idea/vcs.xml中的
<mapping directory="$PROJECT_DIR$" vcs="" />的vcs置爲空,
而後在走正常提交代碼的流程


參考連接:https://blog.csdn.net/u011270542/article/details/54924431;

https://blog.csdn.net/sinat_39150454/article/details/77816179?locationNum=1&fps=1#t3
相關文章
相關標籤/搜索