ubuntu搭建svn、git遇到的問題及解決辦法


不錯的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分支下載到本地,並且切換到本地

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM