git服务器管理代码_git管理系统

hacker|
115

文章目录:

阿里云服务器 怎么用git部署代码

使用阿里云Ubuntu 12.0.4 64位操作系统做git服务器。

首先git服务器有两种访问方式可以选择:http方式和ssh的方式,http方式更容易使用。

1、http方式的git服务器搭建以及使用git命令行访问:

On the Server

1) Install Ubuntu Server, this is the base of our git server obviously

2) Now we need to install a couple of packages, these being ‘git-core’ and ‘apache2′, we do this like so:-

apt-get update

apt-get install apache2 git-core

3) Now we need to create a new folder for your new repository and set some inital permissons, we do this like so:-

cd /var/www

mkdir test-repo.git

cd test-repo.git

git --bare init

git update-server-info

chown -R www-data.www-data .

4) We now need to enable WebDAV on Apache2 of which we will use to serve the repository:-

a2enmod dav_fs

5) We now need to configure the access restrictions to our repository by creating the following file:-

/etc/apache2/conf.d/git.conf

Then fill it in with the following content:-

Location /test-repo.git

DAV on

AuthType Basic

AuthName "Git"

AuthUserFile /etc/apache2/passwd.git

Require valid-user

/Location

Then save and close the file, lets move on to the next bit..

6) Next we need to create a user account of which you will need to use to browse of commit to the repository..

htpasswd -c /etc/apache2/passwd.git user

You could then be prompted to enter the password for the user too and confirm it!

7) Ok that’s it for the server side configuration… we just need to restart Apache2 like so and then we should be ready to move on to the client side stuff!

/etc/init.d/apache2 restart

…you can now move on to the client side stuff!

On the client side

Ok so now we need to create a local (on your desktop machine) repository and then we’ll initiate the new remote repository… So, if your using Linux/MacOSX bring up the terminal and type the following commands:-

mkdir ~/Desktop/test-project

cd ~/Desktop/test-project

git init

git remote add origin ;user@server name or IP address/test-project.git

touch README

git add .

git commit -a -m “Initial import”

git push origin master

Done! – Your intiial file named ‘README’ which currently is just blank has now been committed and you’ve pushed your code to your new git server which has now completed the Git reposity creation process, now in future you can ‘clone’ your resposity like so:-

git clone user@server name or IP address/test-project.git

注意上面连接;user@server name or IP address/test-project.git中的user就是你htpasswd -c /etc/apache2/passwd.git user输入的用户名。

另外新建仓库的时候,只需执行:

cd /var/www

mkdir 项目名

cd 项目名

git --bare init

git update-server-info

chown -R www-data.www-data .

然后在/etc/apache2/conf.d/git.conf中对应添加上面类似段即可。

其中:

AuthUserFile 密码文件名

后面的文件就是你指定的密码文件,你可以

htpasswd -c 密码文件名 user

对应指定该项目的用户名和密码即可。添加用户是不要-c参数:

htpasswd 密码文件名 user

什么是“git”服务器?

1、git是一种分布式的版本管理系统,Linux的创造者Linus写的。

2、GitHub是基于git的代码库托管站,也算是程序员的SMS(以码会友),其中一个主要的开源代码发布或托管站

3、git的作用就是对文件进行版本管理,方便在不同版本进行切换修改,类似文件分不同时间备份让后需要时找回其中一份代替,不过更方便使用。

4、GitHub某种程度上就是代码的网盘,也有开源开发商作为代码发布、存放、征集Bug和意见用。

5、git的特点:

1)就是云的概念,代码可以存在云端git的网站上,就像我们在各种设备间都能浏览到自己存储的网盘文件 一样,我们在各个设备间都能访问到自己的代码。

2)它的社交属性。因为代码是开源的,每个人都可以浏览别人的项目并提出意见,而且它像微博一样,你能粉别人,也能被别人粉。如果你是大牛,如果你或者你的项目够有趣,你就会有很多粉丝,你的项目也会被更多的人star。

3)它能给团队合作带来很大帮助。现在有些公司就是用github来开发项目的。github允许多人多分支的工作,并且标示别人的修改和备注,最后还能合并。

什么是git服务器

Git是一个开源的分布式版本控制系统,可以有效、高速地处理从很小到非常大的项目版本管理。

Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件。

Git的主要功能:

1、查看邮件或者通过其它方式查看一般开发者的提交状态。

2、打上补丁,解决冲突(可以自己解决,也可以要求开发者之间解决以后再重新提交,如果是开源项目,还要决定哪些补丁有用,哪些不用)。

3、向公共服务器提交结果,然后通知所有开发人员。

扩展资料:

Git的优缺点:

优点:

1、适合分布式开发,强调个体。

2、公共服务器压力和数据量都不会太大。

3、速度快、灵活。

4、任意两个开发者之间可以很容易的解决冲突。

5、离线工作。

缺点:

1、资料少(起码中文资料很少)。

2、学习周期相对而言比较长。

3、不符合常规思维。

4、代码保密性差,一旦开发者把整个库克隆下来就可以完全公开所有代码和版本信息。

参考资料来源:百度百科-Git

使用git做代码管理,如何在代码改变的时候自动同步到测试服务器上?

git 有一系列 hook,视具体配置,利用 post-receive hook 或 post-commit hook 即可。

如何将代码上传到git服务器上

1、本地公钥的获取,

cd ~/.ssh

ls

使用指令ssh-keygen,生产公钥,第一个提示时输入文件(默认是id_rsa),第二个提示时输入的是密钥,

公钥放置在id_rsa.pub文件中。

2、按照code的提示,进行代码上传。

2.1  建立一个git文件件,比如git_csdn ,

2.2  git init,建仓操作,

2.3  可以新建一个readme.md, touch README.md

2.4 git add.添加所有文件,git add file,添加file,比如git add README

2.5 git commit -m "first commit"

2.6 git remote add origin git @ url 地址

2.7 git push -u origin master

3、git clone 地址

4、git remote 不带参数,列出已经存在的远程分支

$ git remote

origin

5、配置:

$ git config --global user.name "John Doe"

$ git config --global user.email johndoe@example.com

出现的问题: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

$ git push -u origin master

3.若不想merge远程和本地修改,可以先创建新的分支:

$ git branch [name]

然后push

$ git push -u origin [name]

分支管理:

1、创建分支: git branch  new_branch

2、查看分支:git branch

3、删除分支:git branch  -d new_branch

4、切换分支:git checkout  new_branch

5、创建分支并切换分支: git checkout  -b new_branch即可在本地新建分支,并使用该分支track远程分支

6、提交并推送分支:

git  add .

git  commit -m "xxx"

git  push -u origin new_branch

7、删除远程分支:git  push origin --delete new_branch

8、合并分支: git merge  new_branch

9、将本地更新上传到远程分支上:

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

首先git add newfile.c,

然后git commit -m "add new file",

紧接着git push 本地分支名 远程分支名即可将本地分支更新到远程分支。

10.获取远程分支

git fetch 从远程获取其他用户push上来的新分支

git remote -v  即可查看远程所有的版本信息

服务器上的代码怎么用git管理

首先确保你的本地git工作目录下已经增加了远程分支了使用 git remote -v 查看。如果没有则先使用 git remote add 命令添加一个(假设名为origin,分支为master)。如果已经有了,则使用 git push origin master命令提交当前工作目录下的分支到远程master分支

1条大神的评论

  • avatar
    访客 2022-07-03 上午 11:29:06

    remote -v 查看。如果没有则先使用 git remote add 命令添加一个(假设名为origin,分支为master)。如果已经有了,则使用 git push origin master命令提交当前

发表评论