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
相关文章
相关标签/搜索