Merge pull request #20293 from lxbwolf/34-20201125-Get-started-with-Fossil-an-alternative-to-Git

TSL
This commit is contained in:
geekpi 2020-11-30 08:42:55 +08:00 committed by GitHub
commit f997471136
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 246 additions and 247 deletions

View File

@ -1,247 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (lxbwolf)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Get started with Fossil, an alternative to Git)
[#]: via: (https://opensource.com/article/20/11/fossil)
[#]: author: (Klaatu https://opensource.com/users/klaatu)
Get started with Fossil, an alternative to Git
======
Fossil is an all-in-one version control system, bug tracker, wiki,
forum, and documentation solution.
![Dinosaurs on land at sunset][1]
As any programmer knows, there are many reasons it's vital to keep track of code changes. Sometimes you just want a history of how your project started and evolved, as a matter of curiosity or education. Other times, you want to enable other coders to contribute to your project, and you need a reliable way to merge disparate parts. And more critically, sometimes an adjustment you make to fix one problem breaks something else that was working.
The [Fossil][2] source code management system is an all-in-one version control system, bug tracker, wiki, forum, and documentation solution from the creator of the famous [SQLite][3] database.
### Install Fossil
Fossil is a single, self-contained C program, so you can probably just [download Fossil][4] from its website and place it anywhere in your system [PATH][5]. For example, assuming `/usr/local/bin` is in your path, as it usually is by default:
```
$ wget <https://fossil-scm.org/home/uv/fossil-linux-x64-X.Y.tar.gz>
$ sudo tar xvf fossil-linux-x64-X.Y.tar.gz \
\--directory /usr/local/bin
```
You might also find Fossil in your software repository through your package manager, or you can compile it from source code.
### Create a Fossil repository
If you have a coding project you want to track with Fossil, the first step is to create a Fossil repository:
```
$ fossil init myproject.fossil
project-id: 010836ac6112fefb0b015702152d447c8c1d8604
server-id:  54d837e9dc938ba1caa56d31b99c35a4c9627f44
admin-user: klaatu (initial password is "14b605")
```
Creating a Fossil repo returns three items: a unique project ID, a unique server ID, and an admin ID and password. The project and server IDs are version numbers. The admin credentials establish your ownership of this repository and can be used if you decide to run Fossil as a server for other users to access.
### Work in a Fossil repository
To start working in a Fossil repo, you must create a working location for its data. You might think of this process as creating a virtual environment in Python or unzipping a ZIP file that you intend to zip back up again later.
Create a working directory and change into it:
```
$ mkdir myprojectdir
$ cd myprojectdir
```
Open your Fossil repository into the directory you created:
```
$ fossil open ../myproject
project-name: &lt;unnamed&gt;
repository:   /home/klaatu/myprojectdir/../myproject
local-root:   /home/klaatu/myprojectdir/
config-db:    /home/klaatu/.fossil
project-code: 010836ac6112fefb0b015702152d447c8c1d8604
checkout:     9e6cd96dd675544c58a246520ad58cdd460d1559 2020-11-09 04:09:35 UTC
tags:         trunk
comment:      initial empty check-in (user: klaatu)
check-ins:    1
```
You might notice that Fossil created a hidden file called `.fossil` in your home directory to track your global Fossil preferences. This is not specific to your project; it's just an artifact of the first time you use Fossil.
#### Add files
To add files to your repository, use the `add` and `commit` subcommands. For example, create a simple README file and add it to the repository:
```
$ echo "My first Fossil project" &gt; README
$ fossil add README
ADDED  README
$ fossil commit -m 'My first commit'
New_Version: 2472a43acd11c93d08314e852dedfc6a476403695e44f47061607e4e90ad01aa
```
#### Use branches
By default, a Fossile repository starts with a main branch called `trunk`. You can branch off the trunk when you want to work on code without affecting your primary codebase. Creating a new branch requires the `branch` subcommand, along with a new branch name and the branch you want to use as the basis for your new one. In this example, the only branch is `trunk`, so try creating a new branch called `dev`:
```
$ fossil branch --help
Usage: fossil branch new BRANCH-NAME BASIS ?OPTIONS?
$ fossil branch new dev trunk
New branch: cb90e9c6f23a9c98e0c3656d7e18d320fa52e666700b12b5ebbc4674a0703695
```
You've created a new branch, but your current branch is still `trunk`:
```
$ fossil branch current
trunk
```
To make your new `dev` branch active, use the `checkout` command:
```
$ fossil checkout dev
dev
```
#### Merge changes
Suppose you add an exciting new file to your `dev` branch, and having tested it, you're satisfied that it's ready to take its place in `trunk`. This is called a _merge_.
First, change your branch back to your target branch (in this example, that's `trunk`): 
```
$ fossil checkout trunk
trunk
$ ls
README
```
Your new file (or any changes you made to an existing file) doesn't exist there yet, but that's what performing the merge will take care of:
```
$ fossil merge dev
 "fossil undo" is available to undo changes to the working checkout.
$ ls
myfile.lua  README
```
### View the Fossil timeline
To see the history of your repository, use the `timeline` option. This shows a detailed list of all activity in your repository, including a hash representing the change, the commit message you provided when committing code, and who made the change:
```
$ fossil timeline
=== 2020-11-09 ===
06:24:16 [5ef06e668b] added exciting new file (user: klaatu tags: dev)
06:11:19 [cb90e9c6f2] Create new branch named "dev" (user: klaatu tags: dev)
06:08:09 [a2bb73e4a3] *CURRENT* some additions were made (user: klaatu tags: trunk)
06:00:47 [2472a43acd] This is my first commit. (user: klaatu tags: trunk)
04:09:35 [9e6cd96dd6] initial empty check-in (user: klaatu tags: trunk)
+++ no more data (5) +++
```
![Fossil UI][6]
(Klaatu, [CC BY-SA 4.0][7])
### Make your Fossil repository public
Because Fossil features a built-in web interface, Fossil doesn't need a hosting service like GitLab or Gitea do. Fossil is its own hosting service, as long as you have a server to put it on. Before making your Fossil project public, though, you must configure some attributes through the web user interface (UI).
Launch a local instance with the `ui` subcommand:
```
$ pwd
/home/klaatu/myprojectdir/
$ fossil ui
```
Specifically, look at **Users** and **Settings** for security, and **Configuration** for project properties (including a proper title). The web interface isn't just a convenience function. It's intended for actual use and is indeed used as the host for the Fossil project. There are several surprisingly advanced options, from user management (or self-management, if you please) to single-sign-on (SSO) with other Fossil repositories on the same server.
Once you're satisfied with your changes, close the web interface and press **Ctrl+C** to stop the UI engine from running. Commit your web changes just as you would any other update:
```
$ fossil commit -m 'web ui updates'
New_Version: 11fe7f2855a3246c303df00ec725d0fca526fa0b83fa67c95db92283e8273c60
```
Now you're ready to set up your Fossil server.
1. Copy your Fossil repository (in this example, `myproject.fossil`) to your server. You only need the single file.
2. Install Fossil on your server, if it's not already installed. The process for installing Fossil to your server is the same as it was for your local computer.
3. In your `cgi-bin` directory (or the equivalent of that directory, depending upon which HTTP daemon you're running), create a file called `repo_myproject.cgi`:
```
#!/usr/local/bin/fossil
repository: /home/klaatu/public_html/myproject.fossil
```
Make the script executable:
```
`$ chmod +x repo_myproject.cgi`
```
That's all there is to it. Your project is now live on the internet.
You can visit the web UI by navigating to your CGI script, such as `https://example.com/cgi-bin/repo_myproject.cgi`.
Or you can interact with your repository from a terminal through the same URL:
```
`$ fossil clone https://klaatu@example.com/cgi-bin/repo_myproject.cgi`
```
Working with a local clone requires you to use the `push` subcommand to send local changes back to your remote repository and the `pull` subcommand to get remotely made changes into your local copy:
```
`$ fossil push https://klaatu@example.com/cgi-bin/repo_myproject.cgi`
```
### Use Fossil for independent hosting
Fossil places a lot of power into your hands (and the hands of your collaborators) and makes you independent of hosting services. This article only hints at the basics. There's so much more to Fossil that can help you and your teams in your code projects. Give Fossil a try. It won't just change the way you think about version control; it'll help you stop thinking about version control altogether.
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/11/fossil
作者:[Klaatu][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/klaatu
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/osdc_dinosaur_sunset.png?itok=lbzpbW5p (Dinosaurs on land at sunset)
[2]: https://fossil-scm.org/home/doc/trunk/www/index.wiki
[3]: https://www.sqlite.org/index.html
[4]: https://fossil-scm.org/home/uv/download.html
[5]: https://opensource.com/article/17/6/set-path-linux
[6]: https://opensource.com/sites/default/files/uploads/fossil-ui.jpg (Fossil UI)
[7]: https://creativecommons.org/licenses/by-sa/4.0/

View File

@ -0,0 +1,246 @@
[#]: collector: "lujun9972"
[#]: translator: "lxbwolf"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
[#]: subject: "Get started with Fossil, an alternative to Git"
[#]: via: "https://opensource.com/article/20/11/fossil"
[#]: author: "Klaatu https://opensource.com/users/klaatu"
开始学习 FossilGit 的一个替代品
======
Fossil 是一个集版本控制系统、bug 追踪、维基、论坛以及文档解决方案于一体的系统。
![Dinosaurs on land at sunset][1]
每个开发者都知道,追踪代码的修改是至关重要的。有时候你会处于好奇或者教育的目的需要展示你的项目开始和进化的历史。有时候你想让其他的开发者参与到你的项目中,因此你需要一种值得信赖的能合并不同代码分支的方法。更极端一点,有时候你为了解决一个问题而修改的代码导致已有的功能不能正常使用。
[Fossil][2] 源码管理系统是由著名的 [SQLite][3] 数据库的作者开发的一个集版本控制系统、bug 追踪、维基、论坛以及文档解决方案于一体的系统。
### 安装 Fossil
Fossil 是一个独立的 C 程序,因此你可以从它的网站上[下载][4]后放在环境变量 [PATH][5] 中的任意位置。例如,假定 `/usr/local/bin` 已经在你的环境变量中(默认情况下是在的)
```
$ wget <https://fossil-scm.org/home/uv/fossil-linux-x64-X.Y.tar.gz>
$ sudo tar xvf fossil-linux-x64-X.Y.tar.gz \
\--directory /usr/local/bin
```
你也可以通过包管理器从软件仓库中找到 Fossil或者直接从源码编译。
### 创建一个 Fossil 仓库
如果你已经有一个代码项目,想用 Fossil 来追踪,那么第一步就是创建一个 Fossil 仓库:
```
$ fossil init myproject.fossil
project-id: 010836ac6112fefb0b015702152d447c8c1d8604
server-id:  54d837e9dc938ba1caa56d31b99c35a4c9627f44
admin-user: klaatu (initial password is "14b605")
```
创建 Fossil 仓库的过程中会返回三行信息:一个唯一的项目 ID、一个唯一的服务 ID 以及管理员 ID 和密码。项目 ID 和服务 ID 是版本数字。管理员资质表明你对这个仓库的所有权,当你把这个 Fossil 仓库作为服务器让其他用户来访问时可以使用管理员权限。
### Fossil 仓库工作流
在你使用 Fossil 仓库之前,你需要先为它的数据创建一个工作路径。你可以把这个过程类比为使用 Python 时创建一个虚拟环境或者解压一个只会用来备份的 ZIP 文件。
创建一个工作目录并进入:
```
$ mkdir myprojectdir
$ cd myprojectdir
```
把你的 Fossil 打开到刚刚创建的目录:
```
$ fossil open ../myproject
project-name: &lt;unnamed&gt;
repository:   /home/klaatu/myprojectdir/../myproject
local-root:   /home/klaatu/myprojectdir/
config-db:    /home/klaatu/.fossil
project-code: 010836ac6112fefb0b015702152d447c8c1d8604
checkout:     9e6cd96dd675544c58a246520ad58cdd460d1559 2020-11-09 04:09:35 UTC
tags:         trunk
comment:      initial empty check-in (user: klaatu)
check-ins:    1
```
你可能注意到了Fossil 在你的家目录下创建了一个名为 `.fossil` 的隐藏文件,用来追踪你的全局 Fossil 配置。这个配置不是只适用于你的一个项目的;这个文件只会在你第一次使用 Fossil 时生成。
#### 添加文件
使用 `add``commit` 子命令来向你的仓库添加文件。例如,创建一个简单的 README 文件,把它添加到仓库:
```
$ echo "My first Fossil project" &gt; README
$ fossil add README
ADDED  README
$ fossil commit -m 'My first commit'
New_Version: 2472a43acd11c93d08314e852dedfc6a476403695e44f47061607e4e90ad01aa
```
#### 使用分支
Fossil 仓库开始时默认使用的主分支名为 `trunk`。当你想修改代码而又不影响主干代码时,你可以从 trunk 分支切走。创建新分支需要使用 `branch` 子命令,这个命令需要两个参数:一个新分支的名字,一个新分支的基分支名字。在本例中,只有一个分支 `trunk`,因此尝试创建一个名为 `dev` 的新分支:
```
$ fossil branch --help
Usage: fossil branch new BRANCH-NAME BASIS ?OPTIONS?
$ fossil branch new dev trunk
New branch: cb90e9c6f23a9c98e0c3656d7e18d320fa52e666700b12b5ebbc4674a0703695
```
你已经创建了一个新分支,但是你当前所在的分支仍然是 `trunk`
```
$ fossil branch current
trunk
```
使用 `checkout` 命令切换到你的新分支 `dev`
```
$ fossil checkout dev
dev
```
#### 合并修改
假设你在 `dev` 分支中添加了一个新文件,完成了测试,现在想把它合并到 `trunk`。这个过程叫做*合并*。
首先,切回目标分支(本例中目标分支为 `trunk`
```
$ fossil checkout trunk
trunk
$ ls
README
```
这个分支中没有你的新文件(或者你对其他文件的修改),而那些内容是合并的过程需要的信息:
```
$ fossil merge dev
 "fossil undo" is available to undo changes to the working checkout.
$ ls
myfile.lua  README
```
### 查看 Fossil 时间线
使用 `timeline` 选项来查看仓库的历史。这个命令列出了你的仓库的所有活动的详细信息,包括用来表示每次修改的哈希值、每次提交时填写的信息以及提交者:
```
$ fossil timeline
=== 2020-11-09 ===
06:24:16 [5ef06e668b] added exciting new file (user: klaatu tags: dev)
06:11:19 [cb90e9c6f2] Create new branch named "dev" (user: klaatu tags: dev)
06:08:09 [a2bb73e4a3] *CURRENT* some additions were made (user: klaatu tags: trunk)
06:00:47 [2472a43acd] This is my first commit. (user: klaatu tags: trunk)
04:09:35 [9e6cd96dd6] initial empty check-in (user: klaatu tags: trunk)
+++ no more data (5) +++
```
![Fossil UI][6]
(Klaatu, [CC BY-SA 4.0][7])
### 公开你的 Fossil 仓库
因为 Fossil 有个内置的 web 界面,所以 Fossil 不像 GitLab 和 Gitea 那样需要主机服务。Fossil 就是它自己的主机服务,只要你把它放在一台机器上就行了。在你公开你的 Fossil 仓库之前,你还需要通过 web 用户界面UI来配置一些信息
使用 `ui` 子命令启动一个本地的实例:
```
$ pwd
/home/klaatu/myprojectdir/
$ fossil ui
```
`用户`和`设置`是安全相关的,`配置`是项目属性相关的包括一个合适的标题。web 界面不仅仅是一个方便的功能。 它是能在生产环境中使用并作为 Fossil 项目的宿主来使用的。它还有一些其他的高级选项,比如用户管理(或者叫自我管理)、在同一个服务器上与其他的 Fossil 仓库进行单点登录SSO
当配置完成后,关掉 web 界面并按下 **Ctrl+C** 来停止 UI 引擎。像提交代码一样提交你的 web 修改。
```
$ fossil commit -m 'web ui updates'
New_Version: 11fe7f2855a3246c303df00ec725d0fca526fa0b83fa67c95db92283e8273c60
```
现在你可以配置你的 Fossil 服务器了。
1. 把你的 Fossil 仓库(本例中是 `myproject.fossil`)复制到服务器,你只需要这一个文件。
2. 如果你的服务器没有安装 Fossil就在你的服务器上安装 Fossil。在服务器上安装的过程跟在本地一样。
3. 在你的 `cgi-bin` 目录下(或它对应的目录,这取决于你的 HTTP 守护进程)创建一个名为 `repo_myproject.cgi` 的文件:
```
#!/usr/local/bin/fossil
repository: /home/klaatu/public_html/myproject.fossil
```
添加可执行权限:
```
`$ chmod +x repo_myproject.cgi`
```
你需要做的都已经做完了。现在可以通过互联网访问你的项目了。
你可以通过 CGI 脚本来访问 web UI例如 `https://example.com/cgi-bin/repo_myproject.cgi`
你也可以通过命令行来进行交互:
```
`$ fossil clone https://klaatu@example.com/cgi-bin/repo_myproject.cgi`
```
在本地的克隆仓库中工作时,你需要使用 `push` 子命令把本地的修改推送到远程的仓库,使用 `pull` 子命令把远程的修改拉取到本地仓库:
```
`$ fossil push https://klaatu@example.com/cgi-bin/repo_myproject.cgi`
```
### 使用Fossil 作为独立的主机
Fossil 大大提高了你的效率(也提高了你的合作者的效率),让你不再依赖主机副刷。本文只是简单的介绍了基本概念。你的代码项目还会用到很多有用的 Fossil 功能。尝试一下 Fossil。它不仅会改变你对版本控制的理解它会让你不再考虑其他的版本控制系统。
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/11/fossil
作者:[Klaatu][a]
选题:[lujun9972][b]
译者:[lxbwolf](https://github.com/lxbwolf)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/klaatu
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/osdc_dinosaur_sunset.png?itok=lbzpbW5p "Dinosaurs on land at sunset"
[2]: https://fossil-scm.org/home/doc/trunk/www/index.wiki
[3]: https://www.sqlite.org/index.html
[4]: https://fossil-scm.org/home/uv/download.html
[5]: https://opensource.com/article/17/6/set-path-linux
[6]: https://opensource.com/sites/default/files/uploads/fossil-ui.jpg "Fossil UI"
[7]: https://creativecommons.org/licenses/by-sa/4.0/