使用git工具上传代码文件到新浪云

来源:互联网 发布:战斧乐队 知乎 编辑:程序博客网 时间:2024/05/18 18:00

使用git工具上传代码文件到新浪云

一、在本地创建仓库

在本地新建文件夹,进入该文件夹,鼠标右击打开Git Bash。
输入命令: $ git init(初始化该仓库)

二、添加git远程仓库 sae

$ git remote add sae 新浪云上的仓库地址

三、添加文件

$ git add

四、提交文件

$ git commit

五、将文件上传到服务器

$ git push sae master

最后罗列一些git的常用命令:

1、新建代码库

新建一个目录,将其初始化为Git代码库
$ git init

下载一个项目和它的整个代码历史
$ git clone [url]

2、配置

显示当前的Git配置
$ git config --list

编辑Git配置文件
$ git config -e [--global]

设置提交代码时的用户信息
$ git config [--global] user.name "[name]"
$ git config [--global] user.email "[email address]"

3、增加/删除文件

添加指定文件到暂存区
$ git add [file1] [file2] ...

添加指定目录到暂存区,包括子目录
$ git add [dir]

添加当前目录的所有文件到暂存区
$ git add .

添加每个变化前,都会要求确认
对于同一个文件的多处变化,可以实现分次提交
$ git add -p

删除工作区文件,并且将这次删除放入暂存区
$ git rm [file1] [file2] ...

停止追踪指定文件,但该文件会保留在工作区
$ git rm --cached [file]

改名文件,并且将这个改名放入暂存区
$ git mv [file-original] [file-renamed]

3、代码提交

提交暂存区到仓库区
$ git commit -m [message]

提交暂存区的指定文件到仓库区
$ git commit [file1] [file2] ... -m [message]

提交工作区自上次commit之后的变化,直接到仓库区
$ git commit -a

提交时显示所有diff信息
$ git commit -v

使用一次新的commit,替代上一次提交如果代码没有任何新变化,则用来改写上一次commit的提交信息
$ git commit --amend -m [message]

重做上一次commit,并包括指定文件的新变化
$ git commit --amend [file1] [file2] ...

4、远程同步

下载远程仓库的所有变动
$ git fetch [remote]

显示所有远程仓库
$ git remote -v

显示某个远程仓库的信息
$ git remote show [remote]

增加一个新的远程仓库,并命名
$ git remote add [shortname] [url]

取回远程仓库的变化,并与本地分支合并
$ git pull [remote] [branch]

上传本地指定分支到远程仓库
$ git push [remote] [branch]

强行推送当前分支到远程仓库,即使有冲突
$ git push [remote] --force

推送所有分支到远程仓库
$ git push [remote] --all

0 0