git提交到远程仓库(or部署服务器)

1 篇文章 0 订阅
0 篇文章 0 订阅

总结了4篇前辈们的文章

1.原文地址:http://blog.csdn.net/xdonx/article/details/8860310

git提交远程仓库精简版

2.原文地址:http://www.cnblogs.com/cosiray/archive/2012/06/01/2530967.html

git默认拒绝远程push的解决办法

3. 原文地址:http://www.cnblogs.com/xiaoya901109/archive/2012/08/03/2620664.html

git提交远程仓库复杂版

4.原文连接:http://blog.csdn.net/dengsilinming/article/details/8000622

git命令大全

我就是参考这几篇文章部署服务器 还有github仓库的



原文地址:http://blog.csdn.net/xdonx/article/details/8860310


在已有的Git库中搭建新库,并且将本地的git仓库,上传到远程服务器的git库中,从而开始一个新的项目
首先,在本地新建文件夹abc,进入到abc里面,然后git init。这样就在本地初始化了一个git项目abc。
然后,登录到远程的git服务器上,到gitrepo目录下面,mkdir abc.git。然后进入abc.git目录。git  --bare init。这样就在服务器端建立了一个空的git项目。
之后,在本地,进入到abc目录里面,增加远程仓库。git remote -v 显示项目目前的远程仓库,因为是新建项目,所以结果为空。git remote add origin git://127.0.0.1/abc.git这样就增加了远程仓库abc。
最后commit提交本地代码,git push origin master这样就把本地的git库上传到了远程git服务器的git库中了

也可以不登陆远程直接本地操作

1. git init

2. git add .

3. git commit -am "###"      -------以上3步只是本地提交

4.git remote add origin git@xx.xx.xx.xx:repos/xxx/xxx/xxx.git

5.git push origin 本地分支:远程分支




原文地址:http://www.cnblogs.com/cosiray/archive/2012/06/01/2530967.html


 

在使用Git Push代码到数据仓库时,提示如下错误:

[remote rejected] master -> master (branch is currently checked out)

错误原型

remote: error: refusing to update checked out branch: refs/heads/master

remote: error: By default, updating the current branch in a non-bare repository

remote: error: is denied, because it will make the index and work tree inconsistent

remote: error: with what you pushed, and will require 'git reset --hard' to match

remote: error: the work tree to HEAD.

remote: error:

remote: error: You can set 'receive.denyCurrentBranch' configuration variable to

remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into

remote: error: its current branch; however, this is not recommended unless you

remote: error: arranged to update its work tree to match what you pushed in some

remote: error: other way.

remote: error:

remote: error: To squelch this message and still keep the default behaviour, set

remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.

To git@192.168.1.X:/var/git.server/.../web

! [remote rejected] master -> master (branch is currently checked out)

error: failed to push some refs to 'git@192.168.1.X:/var/git.server/.../web'

解决办法:

这是由于git默认拒绝了push操作,需要进行设置,修改.git/config文件后面添加如下代码:

[receive]
denyCurrentBranch = ignore

无法查看push后的git中文件的原因与解决方法

在初始化远程仓库时最好使用

git --bare init

而不要使用:git init

git init 和git --bare init 的具体区别:http://blog.haohtml.com/archives/12265

=================================================

如果使用了git init初始化,则远程仓库的目录下,也包含work tree,当本地仓库向远程仓库push时, 如果远程仓库正在push的分支上(如果当时不在push的分支,就没有问题), 那么push后的结果不会反应在work tree上,  也即在远程仓库的目录下对应的文件还是之前的内容。

解决方法:

必须得使用命令 git reset --hard 才能看到push后的内容.

研究了很久不得其解,然后找到一条命令凑合着能用了:

登录到 远程的那个文件夹,使用
git config --bool core.bare true

就搞定了。

贴一段参考文章:

Create a bare GIT repository

A small rant: git is unable to create a normal bare repository by itself. Stupid git indeed.

To be precise, it is not possible to clone empty repositories. So an empty repository is a useless repository. Indeed, you normally create an empty repository and immediately fill it:

git init git add .

However, git add is not possible when you create a bare repository:

git --bare init git add .

gives an error "fatal: This operation must be run in a work tree".

You can't check it out either:

Initialized empty Git repository in /home/user/myrepos/.git/ fatal: http://repository.example.org/projects/myrepos.git/info/refs not found: did you run git update-server-info on the server? git --bare init git update-server-info # this creates the info/refs file chown -R <user>:<group> . # make sure others can update the repository

The solution is to create another repository elsewhere, add a file in that repository and, push it to the bare repository.

mkdir temp; cd temp git init touch .gitignore git add .gitignore git commit -m "Initial commit" git push <url or path of bare repository> master cd ..; rm -rf temp





原文地址:http://www.cnblogs.com/xiaoya901109/archive/2012/08/03/2620664.html

 

git用法小结(1)--建立远程仓库

最近一直在学习使用git来管理自己的程序,总是今天东学一点,明天西凑一点,到用的时候,总是有些茫然不知所措。

在博客园里看见一篇老好的文章,教我们做笔记啦,但是做完笔记还是要记得总结哦!

来吧,让我们一起来总结吧,今天先来看看git远程的仓库是怎么建立的。

当然,使用git嘛,第一步肯定是得新建一个git仓库,总得有个操作的空间吧,巧妇难为无米之炊嘛。

1.初始化一个空的git仓库

1 software@debian:~$ mkdir yafeng
2 software@debian:~$ cd yafeng/
3 software@debian:~/yafeng$ ls
4 software@debian:~/yafeng$ git init
5 Initialized empty Git repository in /home/software/yafeng/.git/
6 software@debian:~/yafeng$ 

命令注释:

在上面的命令中,真正去初始化的是第四行的那句---git init

当然,还有很多同学会看见加了参数--bare的命令,这个命令会在我们以后慢慢给大家解释,对于不是作为共享仓库,而是作为一个自己操作的仓库,上面这样就足够了。

好了,现在yafeng目录就是我们的据点---git仓库了哦。

下面我们总要做点什么的吧,入宝山总不能光看着哦:

2.向仓库提交我们写的文件

复制代码
1 software@debian:~/yafeng$ echo "our first git repository" >> file
2 software@debian:~/yafeng$ ls
3 file
4 software@debian:~/yafeng$ git add file
5 software@debian:~/yafeng$ git commit -m "the first file to commit" file
6 [master (root-commit) 0c72641] the first file to commit
7  1 files changed, 1 insertions(+), 0 deletions(-)
8  create mode 100644 file
9 software@debian:~/yafeng$ 
复制代码

命令解释:
我们在仓库中新建了一个文件file,作为我们的示例文件。

第4行:将file文件的信息添加到git仓库的索引库中,并没有真正添加到库。当然上例中的file文件只是我们的示例,它是一个路径,因此,可以是文件,更可以是目录。

第5行:将索引库中的内容向git仓库进行提交。这步之后文件file才算真正提交到拉git仓库中。双引号中的内容是根据每次修改的不同内容,由我们自己去填写的,

很多人会看见

  git commit -a -m “ ”

这条的命令是在你已经add了一个或多个文件过之后,然后修改了这些文件,就可以使用该命令进行提交。

好了,不管怎么样,终于是将文件提交到库了。可是现在的仓库只是一个本地的仓库,我们的目标是变成远程仓库哦,继续吧。

3.在本地仓库添加一个远程仓库,并将本地的master分支跟踪到远程分支

1 software@debian:~/yafeng$ git remote add origin ssh://software@172.16.0.30/~/yafeng/.git
2 software@debian:~/yafeng$ git push origin master
3 software@172.16.0.30's password: 
4 Everything up-to-date
5 software@debian:~/yafeng$ 

命令注释:

第1行:在本地仓库添加一个远程仓库,当然ssh后面的地址是我们本地仓库的地址.

第2行:将本地master分支跟踪到远程分支,在git仓库建立之初就会有一个默认的master分支,当然你如果建立了其他分支,也可以用同样的方法去跟踪.

对于分支的事情,我们会在以后细细的讲述.

做到拉这一步了吗?我告诉你,你已经完成目的了哦,现在的git仓库已经是一个远程仓库了,

不相信吗?我们来测试一次阿:

4.测试

现在本机上看看:

复制代码
 1 software@debian:~/yafeng$ git remote show origin
 2 software@172.16.0.30's password: 
 3 * remote origin
 4   Fetch URL: ssh://software@172.16.0.30/~/yafeng/.git
 5   Push  URL: ssh://software@172.16.0.30/~/yafeng/.git
 6   HEAD branch: master
 7   Remote branch:
 8     master tracked
 9   Local ref configured for 'git push':
10     master pushes to master (up to date)
11 software@debian:~/yafeng$ 
复制代码

代码注释:

第1行:显示远程信息

很多看见这还是会不以为然的,这又能说明什么呢?好,那就来点实际的:

在另一个机子上,远程clone

复制代码
 1 root@yafeng-VirtualBox:~# ls
 2 bin  gittest  read_temp
 3 root@yafeng-VirtualBox:~# git clone ssh://software@172.16.0.30/~/yafeng/.git
 4 Cloning into yafeng...
 5 software@172.16.0.30's password: 
 6 remote: Counting objects: 9, done.
 7 remote: Compressing objects: 100% (3/3), done.
 8 remote: Total 9 (delta 0), reused 0 (delta 0)
 9 Receiving objects: 100% (9/9), done.
10 root@yafeng-VirtualBox:~# ls
11 bin  gittest  read_temp  yafeng
12 root@yafeng-VirtualBox:~# cd yafeng/
13 root@yafeng-VirtualBox:~/yafeng# ls
14 file
15 root@yafeng-VirtualBox:~/yafeng# 
复制代码

代码注释:

第3行:就是远程clone仓库.很明显的对比可以知道多了yafeng目录,而这个yafeng目录里的内容和我们另外一台机子上的内容一样

至此,一个简单的git远程仓库就建好了,简单不,试试吧!!






原文连接:http://blog.csdn.net/dengsilinming/article/details/8000622


Git 是一个很强大的分布式版本控制系统。它不但适用于管理大型开源软件的源代码,管理私人的文档和源代码也有很多优势。

Git常用操作命令:

1) 远程仓库相关命令

检出仓库:$ git clone git://github.com/jQuery/jquery.git

查看远程仓库:$ git remote -v

添加远程仓库:$ git remote add [name] [url]

删除远程仓库:$ git remote rm [name]

修改远程仓库:$ git remote set-url --push [name] [newUrl]

拉取远程仓库:$ git pull [remoteName] [localBranchName]

推送远程仓库:$ git push [remoteName] [localBranchName]

 

*如果想把本地的某个分支test提交到远程仓库,并作为远程仓库的master分支,或者作为另外一个名叫test的分支,如下:

$git push origin test:master         // 提交本地test分支作为远程的master分支

$git push origin test:test              // 提交本地test分支作为远程的test分支

 

2)分支(branch)操作相关命令

查看本地分支:$ git branch

查看远程分支:$ git branch -r

创建本地分支:$ git branch [name] ----注意新分支创建后不会自动切换为当前分支

切换分支:$ git checkout [name]

创建新分支并立即切换到新分支:$ git checkout -b [name]

删除分支:$ git branch -d [name] ---- -d选项只能删除已经参与了合并的分支,对于未有合并的分支是无法删除的。如果想强制删除一个分支,可以使用-D选项

合并分支:$ git merge [name] ----将名称为[name]的分支与当前分支合并

创建远程分支(本地分支push到远程):$ git push origin [name]

删除远程分支:$ git push origin :heads/[name] 或 $ gitpush origin :[name] 

 

*创建空的分支:(执行命令之前记得先提交你当前分支的修改,否则会被强制删干净没得后悔)

$git symbolic-ref HEAD refs/heads/[name]

$rm .git/index

$git clean -fdx

 

3)版本(tag)操作相关命令

查看版本:$ git tag

创建版本:$ git tag [name]

删除版本:$ git tag -d [name]

查看远程版本:$ git tag -r

创建远程版本(本地版本push到远程):$ git push origin [name]

删除远程版本:$ git push origin :refs/tags/[name]

合并远程仓库的tag到本地:$ git pull origin --tags

上传本地tag到远程仓库:$ git push origin --tags

创建带注释的tag:$ git tag -a [name] -m 'yourMessage'

 

4) 子模块(submodule)相关操作命令

添加子模块:$ git submodule add [url] [path]

   如:$git submodule add git://github.com/soberh/ui-libs.git src/main/webapp/ui-libs

初始化子模块:$ git submodule init  ----只在首次检出仓库时运行一次就行

更新子模块:$ git submodule update ----每次更新或切换分支后都需要运行一下

删除子模块:(分4步走哦)

 1) $ git rm --cached [path]

 2) 编辑“.gitmodules”文件,将子模块的相关配置节点删除掉

 3) 编辑“ .git/config”文件,将子模块的相关配置节点删除掉

 4) 手动删除子模块残留的目录

 

5)忽略一些文件、文件夹不提交

在仓库根目录下创建名称为“.gitignore”的文件,写入不需要的文件夹名或文件,每个元素占一行即可,如

target

bin

*.db

 

=====================

Git 常用命令

git branch 查看本地所有分支
git status 查看当前状态 
git commit 提交 
git branch -a 查看所有的分支
git branch -r 查看本地所有分支
git commit -am "init" 提交并且加注释 
git remote add origin git@192.168.1.119:ndshow
git push origin master 将文件给推到服务器上 
git remote show origin 显示远程库origin里的资源 
git push origin master:develop
git push origin master:hb-dev 将本地库与服务器上的库进行关联 
git checkout --track origin/dev 切换到远程dev分支
git branch -D master develop 删除本地库develop
git checkout -b dev 建立一个新的本地分支dev
git merge origin/dev 将分支dev与当前分支进行合并
git checkout dev 切换到本地dev分支
git remote show 查看远程库
git add .
git rm 文件名(包括路径) 从git中删除指定文件
git clone git://github.com/schacon/grit.git 从服务器上将代码给拉下来
git config --list 看所有用户
git ls-files 看已经被提交的
git rm [file name] 删除一个文件
git commit -a 提交当前repos的所有的改变
git add [file name] 添加一个文件到git index
git commit -v 当你用-v参数的时候可以看commit的差异
git commit -m "This is the message describing the commit" 添加commit信息
git commit -a -a是代表add,把所有的change加到git index里然后再commit
git commit -a -v 一般提交命令
git log 看你commit的日志
git diff 查看尚未暂存的更新
git rm a.a 移除文件(从暂存区和工作区中删除)
git rm --cached a.a 移除文件(只从暂存区中删除)
git commit -m "remove" 移除文件(从Git中删除)
git rm -f a.a 强行移除修改后文件(从暂存区和工作区中删除)
git diff --cached 或 $ git diff --staged 查看尚未提交的更新
git stash push 将文件给push到一个临时空间中
git stash pop 将文件从临时空间pop下来
---------------------------------------------------------
git remote add origin git@github.com:username/Hello-World.git
git push origin master 将本地项目给提交到服务器中
-----------------------------------------------------------
git pull 本地与服务器端同步
-----------------------------------------------------------------
git push (远程仓库名) (分支名) 将本地分支推送到服务器上去。
git push origin serverfix:awesomebranch
------------------------------------------------------------------
git fetch 相当于是从远程获取最新版本到本地,不会自动merge
git commit -a -m "log_message" (-a是提交所有改动,-m是加入log信息) 本地修改同步至服务器端 :
git branch branch_0.1 master 从主分支master创建branch_0.1分支
git branch -m branch_0.1 branch_1.0 将branch_0.1重命名为branch_1.0
git checkout branch_1.0/master 切换到branch_1.0/master分支
du -hs

-----------------------------------------------------------
mkdir WebApp
cd WebApp
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin git@github.com:daixu/WebApp.git
git push -u origin master

 

Git 常用命令图表 


图片转自:http://www.cnblogs.com/1-2-3/archive/2010/07/18/git-commands.html

本文转自:http://hi.baidu.com/sunboy_2050/item/ffab7396672895d11a49dfcc

建议参考文献:

Git 命令参数及用法详解

Windows环境中使用版本管理工具Git

GitRef

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值