ubuntu搭建svn、git遇到的问题及解决办法

简介: 不错的git笔记博客: http://www.cnblogs.com/wanqieddy/category/406859.html http://blog.csdn.net/zxncvb/article/details/22153019 Git学习教程(六)Git日志   http://fsjoy.

不错的git笔记博客:

http://www.cnblogs.com/wanqieddy/category/406859.html

http://blog.csdn.net/zxncvb/article/details/22153019

Git学习教程(六)Git日志

 

http://fsjoy.blog.51cto.com/318484/245261/

图解git

http://my.oschina.net/xdev/blog/114383

 

Git详解之三:Git分支

http://blog.jobbole.com/25877/

情况一、

svn: /opt/svndata/repos/conf/svnserve.conf:12: Option expected

原因:svn不识别配置文件中  开头带空格的参数

权限配置:

#分组:
[groups]
group_admin = wws,aaa,bbb
group_user1 = sj,ccc
group_user2 = sy,dd,eeee
group_user3 = lxt
group_user4 = ss

#设置对根(即SVN)目录下,所有版本库的访问权限
[/]
* = r #所有登录用户默认权限为只读
@group_admin = rw #可以分配给组,该组有读写权限
wws = rw #也可以像这样分配给指定用户

在修改配置文件(authz)后,客户端可能会报“Invalid authz configuration”的错误提示!
客户端没有提示错误原因,但在服务器端有一个方法,可以检查配置文件(authz)错在了哪里;
具体方法如下:
root@server:~# svnauthz-validate /data/svn/LQPLAY/conf/authz
svnauthz-validate: /data/svn/LQPLAY/conf/authz:167: Option must end with ':' or '='
它查出了是配置文件(authz)的第167行,出现了错误。
然后,可以用如下命令,编辑它并保存:
root@server:~# vi /data/svn/LQPLAY/conf/authz
Shift+: set number          (显示行号)
Shift+: 167            (直接跳转到167行)
我发现是本该写为(gaojs = rw),不小心写成了(gaojs - rw)。
字母键(I-Insert),从浏览模式,切换到插入模式;
(Shift+:, 从浏览模式,切换到底行命令模式)
(Esc,从其他模式,退出到浏览模式)
修改后保存退出!
Shift+: wq             (Write & Quit)

 情况二、SVN的“Invalid authz configuration”错误的解决方法

转自:http://blog.csdn.net/gaojinshan/article/details/18218009

查看SVN的目录在哪里?
root@server:~# whereis svn
svn: /usr/bin/svn /usr/bin/X11/svn /usr/share/man/man1/svn.1.gz
查看SVN的进程是哪些?
root@server:~# ps aux | grep svn               
root      1527  0.0  0.0  69640  1092 ?        Ss   10:53   0:00 svnserve -d -r /data/svn/LQPLAY
root      5144  0.0  0.0  13592   936 pts/2    S+   11:58   0:00 grep --color=auto svn
启动SVN的服务(-d:Deamon; -r:Root)
root@server:~# svnserve -d -r /data/svn/LQPLAY
查看SVN的服务是否正常(端口号3690是否存在)
root@server:~# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:3690            0.0.0.0:*               LISTEN      1527/svnserve 

 

1、checkout时,提示:URL svn://192.168.1.99/svntest doesn't exist...

奇怪,怎么会提示库不存在呢?肯定是哪里配置问题。后来尝试了半天,也在网上搜索了很久,终于发现问题所在。

如果你的svn库的路径为:/home/svn/svntest

那么你启动时,不能用命令:

svnserve -d -r /home/svn/svntest

而要用命令:

svnserve -d -r /home/svn/

2、commit时,提示:Authorization failed

开始一直以为是authz文件配置得不对,一直尝试,一直修改,还是不行,郁闷了。在确定authz的配置完全没问题后,开始查其它两个配置文件的问题。后来终于发现问题出在svnserve.conf这个文件。以下四行:

# anon-access = read
# auth-access = write
# password-db = passwd
# authz-db = authz

是被注释掉的,虽然文件说明里面说默认就是按注释掉的配置来执行,但好像并不是这样。放开注释:

anon-access = read
auth-access = write
password-db = passwd
authz-db = authz

问题解决。

PS:有些童鞋问文件上传到服务器后存放在服务器的哪个地方。

答:一般放在/home/svn/svntest/db/revs(根据我自己的目录结构)里面

 

svn: No repository found in 'svn:..解决方案

svn服务未启动或者是启动的时候未指定svn仓库路径

使用如下命令:

sudo svnserve -d -r /var/svn

后面的目录是你svn服务的仓库路径

另外要使用sudo取得管理员权限,否则可能在提交代码的时候出现权限问题

 

git commit命令的使用与git默认编辑器的修改

1、git commit

此时是进入GUN nano编辑器。在这里可以添加你的commit imformation 然后ctrl+o,回车保存,再ctrl+x退出。

因为对Nano编辑器很不熟悉,在这里我想将默认编辑器改为vim。打开.git/config文件,在core中添加 editor=vim即可。

或者运行命令 git config –global core.editor vim 修改更加方便。

2、git commit -a

把所有add了的文件都加入commit,然后进入编辑器编辑commit信息。

3、git commit -m  “commit imformation”

直接在后面添加commit 信息然后提交commit,与gitcommit相比快捷方便,但是就是commit信息格式无法控制。

4、git commit --amend 

修改最后一次commit的信息

 

 

git config运用

本文中所演示的git操作都是在v1.7.5.4版本下进行的,不同的版本会有差异,更老的版本有些选项未必支持。
 
当我们安装好git软件包,或者着手在一个新的机子上使用git的时候,我们首先需要进行一些基本的配置工作,这个就要用到git config。
 
git config是用于进行一些配置设置,有三种不同的方式来指定这些配置适用的范围:
1) git config             针对一个git仓库
2) git config --global    针对一个用户
3) sudo git config --system    针对一个系统,因为是针对整个系统的,所以必须使用sudo
 
 
1) 第一种默认当前目录是一个git仓库,假设我们有一个仓库叫git_test,它所修改配置保存在git_test/.git/config文件,如果当前目录不是一个有效的git仓库,在执行‪一些命令时会报错,例如:
$git config -e
fatal: not in a git directory
 
我们来看一个简单的例子,一般我们clone一个git仓库,默认都是一个工作目录,那么对应的配置变量 bare = false。来看一个很简单的仓库的config文件,cat git_test/.git/config
 
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
 
如果我们想修改bare为false,最简单的办法就是直接用vim打开git_test/.git/config文件进行修改,另一种办法就是使用git config来修改
 
$git config core.bare true
$cat .git/config
[core]
        repositoryformatversion = 0
        filemode = true
        bare = true
        logallrefupdates = true
 
命令的格式就是 git config <section>.<key> <value>。需要注意的是我们没有加--system和--global,那么这个修改只针对于当前git仓库,其它目录的仓库不受影响。
 
2) 第2种是适用于当前用户,也就是说只要是这个用户操作任何git仓库,那么这个配置都会生效,这种配置保存在~/.gitconfig当中,那什么样的配置需要放到用户的配置文件里呢,git里一个最为重要的信息就是提交者的个人信息,包括提交者的名字,还有邮箱。当我们在用git提交代码前,这个是必须要设置的。显而易见,这个配置需要放在用户一级的配置文件里。
$git config --global user.name "I Love You"
$git config --global user.email "i.love.you@gmail.com"
$cat ~/.gitconfig
[user]
        name = I Love You
        email = i.love.you@gmail.com
 
3) 第3种是适用于一个系统中所有的用户,也就是说这里的配置对所有用户都生效,那什么样的配置需要放在这里呢,比如我们在执行git commit会弹出一个默认的编辑器,一般是vim,那作为系统的管理员,可以将vim设置为所有用户默认使用的编辑器,我们来看设置的过程
$sudo git config --system core.editor vim
$cat /etc/gitconfig
[core]                                                                                                                                                                       
        editor = vim
 
我们可以看到它修改的是全局的配置文件/etc/gitconfig。
 
总结:
 
现在我们就会有一个问题,当我们在不同的配置文件中,对同一个变量进行了设置,最终哪个会生效呢?或者说谁到底覆盖谁呢?先来排除一种情况,就是分属不同的两个git仓库的config文件中的配置是互不影响的,这个很好理解。那么要讨论是如果一个配置出即出现在/etc/gitconfig,~/.gitconfig以及git_test/.git/config这三个位置时,我们又恰巧要操作git仓库git_test,那么生效的优先级顺序是(1)git_test/.git/config,(2)~/.gitconfig,(3)/etc/gitconfig,也就是说如果同一个配置同时出现在三个文件中时,(1)有效。
 
 
那么为什么会有这样的情况发生呢,比如我们前面的有关编辑器设置,系统管理员为所有用户设置了默认的编辑器是vim,但是并不是每个用户都习惯用vim,有些人更青睐于功能更炫的emacs(I hate it,我刚刚接触linux的时候上来就是用的emacs,让我这个新手不知所措,但是后来使了vim,觉得更容易上手,而且用的时间长了,对vim了解更深,发现它功能一样强大,而且它可以算是类unix系统中默认的编辑器),言归正传,如果你想用emacs,你就可以将这个配置加入到你的~/.gitconfig中,这样它就会覆盖系统/etc/gitconfig的配置,当然这只针对于你,其他用户如果不设置还是会用vim。
 
$git config --global core.editor emacs
$cat ~/.gitconfig
[core]
        editor = emacs
 
 
对于git config只介绍到这,其实除了以上讲解的部分,它还有很多功能。本文中主要是针对介绍不同范围内设置的配置的有效范围,了解它之后,当以后需要对git进行环境配置时,你就明白根据当前配置的性质,明白是该放在git_test/.git/config,还是在~/.gitconfig,又或是在/etc/gitconfig中,作为一个资深的版本管理者来说,必须要了解以上的区别。

 

 

"remote:error:refusing to update checked out branch:refs/heads/master"的解决办法

在使用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

 

 

git diff 无效的解决

转自:http://blog.csdn.net/rainysia/article/details/49463753

昨天打算把git diff 关联上bcompare作两个文件对比, 后来发现不怎么好用. 还要弹个gtk的窗口. 于是unset了后.

今天重新git diff的时候, 发现输入后没有任何反应. 就记录下怎么修复的

找了一台可以用git diff的机器, 随便echo 了一个多余的字符进已有的repository, 这里我们用strace来追踪执行过程.

#strace -f -e execve git diff
execve("/usr/bin/git", ["git", "diff"], [/* 45 vars */]) = 0 Process 27865 attached [pid 27865] execve("/usr/lib/git-core/pager", ["pager"], [/* 49 vars */]) = -1 ENOENT (No such file or directory) [pid 27865] execve("/usr/local/bin/pager", ["pager"], [/* 49 vars */]) = -1 ENOENT (No such file or directory) [pid 27865] execve("/usr/bin/pager", ["pager"], [/* 49 vars */]) = 0 diff --git a/fabfile.py b/fabfile.py index e53e07a..0974ee9 100644 --- a/fabfile.py +++ b/fabfile.py @@ -176,3 +176,4 @@ def test(version='', by='TAG'): _push_rpm(rpmfile=rpmfile) # done return +122 [pid 27865] +++ exited with 0 +++ --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=27865, si_uid=1000, si_status=0, si_utime=0, si_stime=0} --- +++ exited with 0 +++

 

再看看不能执行的

#strace -f -e execve git diff
execve("/usr/bin/git", ["git", "diff"], [/* 44 vars */]) = 0 Process 20460 attached [pid 20460] execve("/usr/lib/git-core/less", ["less"], [/* 47 vars */]) = -1 ENOENT (No such file or directory) [pid 20460] execve("/usr/local/bin/less", ["less"], [/* 47 vars */]) = -1 ENOENT (No such file or directory) [pid 20460] execve("/usr/bin/less", ["less"], [/* 47 vars */]) = 0 [pid 20460] +++ exited with 0 +++ --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=20460, si_uid=1000, si_status=0, si_utime=0, si_stime=0} --- +++ exited with 0 +++

原来是正常的pager给换成了less. 
这就简单了,找了下/etc/gitconfig. /root/.gitconfig, /home/username/.gitconfig 以及项目下的.git/config 都没有发现alias pager=less的. 看看git config –list 也没有定义.

想起来改过bashrc, 打开一看, 果然

export PAGER=less

删掉后重新加载terminal, git diff就恢复了正常.

 

Double Hyphens in Git Diff

 转自:http://www.microsofttranslator.com/bv.aspx?ref=SERP&br=ro&mkt=zh-CN&dl=zh&lp=EN_ZH-CHS&a=http%3a%2f%2fvincenttam.github.io%2fblog%2f2014%2f08%2f07%2fdouble-hyphens-in-git-diff%2f

Two months ago, I wrote my first list of Git commands, and said that I didn’t know how to use Git commands to view the changes.1

Now, I can understand how one can “use ‘--’ to separate paths from revisions [or branches]”.

For example, if a developer relies on this Git cheatsheet for blogging with Octopress, then he/she will learn some Git commands, for example:

  1. git diff <branch> to view the uncommitted changes;
  2. git diff <path> to show the uncommitted changes in files under <path>.

Those commands should be enough for most cases. However, if he/she blogs with Octopress, then he/she will encounter the some problems:

  1. git diff source can’t view the uncommitted changes on source branch; (Click the linked post in footnote 1 for the error thrown by Git.)
  2. git diff source can’t show the uncommitted changes in files under source folder.

In order to use git diff to do the intended task, one has to avoid ambiguity.

  1. If necessary, one can use -- to separate branch name(s) from file/path names;
  2. 一个可以使用./source到平均source文件夹。
$ git diff origin/source source
fatal: ambiguous argument 'source': both revision and filename
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
$ git diff origin/source source --  # correct command
$ git diff ./source                 # correct command

如果一个想要在 shell 命令中键入,其中一个可以考虑使用fugitive.vim: 在一个窗口由调用:Gst,在修改后的文件在哪里显示的线按D 。

 

将本地test分支push到远程仓库上,如果远程没有就会创建

git push origin test

git checkout test -------》将远程的test分支下载到本地

git checkout -b aa origin/test -----》 将远程的test分支下载到本地,并且切换到本地

 

【作者】 张昺华
【新浪微博】 张昺华--sky
【twitter】 @sky2030_
【facebook】 张昺华 zhangbinghua
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
目录
相关文章
|
安全 Ubuntu Shell
Ubuntu下使用Git_6
这回真的是最后一篇了,哈哈,改写提交。
100 0
Ubuntu下使用Git_6
|
Ubuntu 开发工具 数据库
Ubuntu下使用Git_5
还欠大家最后一篇Git的学习。
70 0
Ubuntu下使用Git_5
|
Ubuntu 开发工具 数据库
Ubuntu下使用Git_4
在这个第四个文章中,我将练习GIT的高级阶段了,由于高级阶段的内容转的比较多,我自己的代码除了我自己可以看懂意外,大家可能看不懂,所以我将会按照
120 0
Ubuntu下使用Git_4
|
Ubuntu 数据库
Ubuntu下使用Git_3
这里是我举得小白阶段比较困难的地方了,
91 0
Ubuntu下使用Git_3
|
Ubuntu 开发工具 数据库
Ubuntu下使用Git_2
接着上一篇的写,这里练习一下git clone 指令
92 0
Ubuntu下使用Git_2
|
存储 Ubuntu 开发工具
Ubuntu下使用Git_1
这里小小的记录一下我在Ubuntu下使用版本控制工具Git的过程。在学习使用Git的时候,我发现了一个很好的网站,这里分享一下,大家共同学习。
117 0
Ubuntu下使用Git_1
|
3天前
|
Ubuntu Linux Python
Linux(15)Ubuntu安装ninja构建工具
Linux(15)Ubuntu安装ninja构建工具
13 0
|
28天前
|
Ubuntu NoSQL 关系型数据库
Ubuntu系统下安装常用软件
Ubuntu系统下安装常用软件
58 0
Ubuntu系统下安装常用软件
|
29天前
|
Ubuntu 关系型数据库 MySQL
Ubuntu 中apt 安装MySQL数据库
Ubuntu 中apt 安装MySQL数据库
69 0
|
3天前
|
Ubuntu Linux 数据安全/隐私保护
Linux(7)Ubuntu20.04 arm64安装Docker
Linux(7)Ubuntu20.04 arm64安装Docker
14 0