Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu Wang 2020-12-12 17:59:07 +08:00
commit 6fefaab218
5 changed files with 209 additions and 219 deletions

View File

@ -0,0 +1,94 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-12911-1.html)
[#]: subject: (Keep track of multiple Git remote repositories)
[#]: via: (https://opensource.com/article/20/11/multiple-git-repositories)
[#]: author: (Peter Portante https://opensource.com/users/portante)
跟踪多个 Git 远程仓库
======
> 拥有一致的命名标准是保持本地和上游 Git 仓库保持一致的关键。
![](https://img.linux.net.cn/data/attachment/album/202012/11/220828tjt9qlpmg1opvibq.jpg)
当本地 Git 仓库的命名与远程仓库不一致时,与远程仓库协作就会变得很混乱。
解决此问题的一个方法是标准化两个词的使用和含义:`origin` 指的是你个人的 `example.com/<USER>/*` 仓库,而 `upstream` 指的是你从 `origin` 仓库<ruby>复刻<rt>fork</rt></ruby>出来的 `example.com` 仓库。换句话说,`upstream` 指的是公开提交工作的上游仓库,而 `origin` 指的是你对上游仓库的本地复刻,例如,你从这里生成<ruby>拉取请求<rt>pull request</rt></ruby>PR
以 [pbench][2] 仓库为例,下面是一个逐步建立新的本地克隆的方法,其中 `origin``upstream` 的定义是一致的。
1、在大多数 Git 托管服务上,当你想在上面工作时,必须对它进行复刻。当你运行自己的 Git 服务器时,这并不是必要的,但对于一个公开的代码库来说,这是一个在贡献者之间传输差异的简单方法。
创建一个 Git 仓库的复刻。在这个例子中,假设你的复刻位于 `example.com/<USER>/pbench`
2、接下来你必须获得一个统一资源标识符 [URI][3]),以便通过 SSH 进行<ruby>克隆<rt>cloning</rt></ruby>。在大多数 Git 托管服务上,比如 GitLab 或 GitHub它在一个标有 “Clone” 或 “Clone over SSH” 的按钮或面板上,可以将克隆 URI 复制到剪贴板中。
3、在你的开发系统中使用你复制的 URI 克隆仓库:
```
$ git clone git@example.com:<USER>/pbench.git
```
这将以默认名称 `origin` 来克隆 Git 仓库,作为你的 `pbench` 仓库复刻副本。
4、切换到刚才克隆的目录
```
$ cd ~/pbench
```
5、下一步获取源仓库的 SSH URI你最初复刻的那个。这可能和上面的方法一样。找到 “Clone” 按钮或面板,复制克隆地址。在软件开发中,这通常被称为“上游”,因为(理论上)这是大多数提交发生的地方,而你打算让这些提交流向下游的仓库。
6、将 URI 添加到你的本地仓库中。是的,将有*两个不同*的远程仓库分配给你的本地仓库副本:
```
$ git remote add upstream git@example.com:bigproject/pbench.git
```
7、现在你有两个命名远程仓库`origin` 和 `upstream`。 你可以用 `remote` 子命令查看你的远程仓库:
```
$ git remote -v
```
现在,你的本地 `master` 分支正在跟踪 `origin``master`,这不一定是你想要的。你可能想跟踪这个分支的 `upstream` 版本,因为大多数开发都在上游进行。这个想法是,你要在从上游获得的内容的基础上添加更改。
8、将你的本地的 `master` 分支改成跟踪 `upstream/master`
```
$ git fetch upstream
$ git branch --set-upstream-to=upstream/master master
```
你可以对任何你想要的分支这样做,而不仅仅是 `master`。例如,有些项目使用 `dev` 分支来处理所有不稳定的变化,而将 `master` 保留给已批准发布的代码。
9、一旦你设置了你的跟踪分支一定要变基`rebase`)你的 `master` 分支,使它与上游仓库的任何新变化保持一致:
```
$ git remote update
$ git checkout master
$ git rebase
```
这是一个保持 Git 仓库在不同复刻之间同步的好方法。如果你想自动完成这项工作,请阅读 Seth Kenlon 关于[使用 Ansible 托管 Git 仓库][4]的文章。
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/11/multiple-git-repositories
作者:[Peter Portante][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/portante
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/rh_003588_01_rd3os.combacktoschoolseriesk12_rh_021x_0.png?itok=fvorN0e- (Digital hand surrounding by objects, bike, light bulb, graphs)
[2]: https://github.com/distributed-system-analysis/pbench
[3]: https://en.wikipedia.org/wiki/Uniform_Resource_Identifier
[4]: https://opensource.com/article/19/11/how-host-github-gitlab-ansible

View File

@ -1,8 +1,8 @@
[#]: collector: (lujun9972)
[#]: translator: (wxy)
[#]: reviewer: (wxy)
[#]: publisher: ( )
[#]: url: ( )
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-12912-1.html)
[#]: subject: (Getting started with Fedora CoreOS)
[#]: via: (https://fedoramagazine.org/getting-started-with-fedora-coreos/)
[#]: author: (Clément Verna https://fedoramagazine.org/author/cverna/)
@ -10,7 +10,7 @@
Fedora CoreOS 入门
======
[Fedora CoreOS入门][1]
![Fedora CoreOS入门][1]
现在被称为 DevOps 时代,操作系统的关注度似乎比工具要低一些。然而,这并不意味着操作系统没有创新。(编辑注:基于 Linux 内核的众多发行版所提供的多样化产品就是一个很好的例子)。[Fedora CoreOS][4] 就对这个 DevOps 时代的操作系统应该是什么样有着独特的理念。

View File

@ -1,114 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (Mjseven)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to Save the Output of a Command to a File in Linux Terminal [Beginners Tip])
[#]: via: (https://itsfoss.com/save-command-output-to-file-linux/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
How to Save the Output of a Command to a File in Linux Terminal [Beginners Tip]
======
When you run a command or script in the Linux terminal, it prints the output on the screen for your immediate viewing.
There will be times when you need to save the output to a file for future references. Now, [you can surely copy and paste in Linux terminal][1] but there are better ways to save the output of a shell script or command in Linux command line. Let me show them to you.
### Method 1: Use redirection to save command output to file in Linux
You can [use redirection in Linux for this purpose][2]. With redirection operator, instead of showing the output on the screen, it goes to the provided file.
* The &gt; redirects the command output to a file replacing any existing content on the file.
* The &gt;&gt; redirects adds the command output at the end of the existing content (if any) of the file.
Use the STDOUT redirection operator &gt; for redirecting the output to a file like this:
```
command > file.txt
```
If the file.txt doesnt exist, it will be created automatically. If you use the &gt; redirect again with the same file, the file content is replaced by the new output.
The example below demonstrates it better. It first saves the output of _ls -l_ command. And then later, it replaces the content of the file with the output of _ls *.c_ command.
![Redirecting command output to file][3]
If you dont want to lose the content of the existing file while saving the output of a script or command, use the redirection operation in append mode with &gt;&gt;.
```
command >> file.txt
```
This example demonstrates it better:
![Redirecting command output to file in append mode][4]
Even here if the file doesnt exist, it is created automatically.
Bonus Tip: Save Linux command output as well as error to a file
If your Linux command returns an error, it doesnt get saved in the file. You can save both the command output and command error in the same file using 2&gt;&amp;1 like this:
**command &gt; file.txt 2&gt;&amp;1**
Basically, 0 stands for standard input, 1 for standard output and 2 for standard error. Here, you are redirecting (&gt;) standard error (2) to same address (&amp;) as standard output (1).
### Method 2: Use tee command to display the output and save it to a file as well
By the way, did you notice that when you send the command output to a file, you cannot see it anymore on the display? The [tee command in Linux][5] solves this problem for you.
Like a tee pipe that sends water stream into two directions, the tee command send the output to the display as well as to a file (or as input to another command). You can use it like this:
```
command | tee file.txt
```
Again, the file will be created automatically, if it doesnt exist already.
You may also use the tee command in append mode with option -a in this manner:
```
command | tee -a file.txt
```
Let me demonstrate it with some easy to follow examples:
![][6]
I have used simple Linux commands in my examples. But rest assured, you can use these methods to save the output of bash scripts as well.
### Note: Avoid pipe pitfall while saving command output to file
You probably are familiar with pipe redirection. You may use it to combine Linux commands but you cannot pipe the output to a file. It will result in error that filename command not found:
![][7]
This is because pipe redirects the output of one command to input of another command. And in this case, you give it a file name while it was expecting a command.
If you are new to Linux command line, I hope this quick tutorial added to your Linux knowledge a bit. [I/O redirection][8] is an essential concept that one should be aware of.
As always, questions and suggestions are always welcome.
--------------------------------------------------------------------------------
via: https://itsfoss.com/save-command-output-to-file-linux/
作者:[Abhishek Prakash][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://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://itsfoss.com/copy-paste-linux-terminal/
[2]: https://linuxhandbook.com/redirection-linux/
[3]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/11/redirecting_command_output_to_file_in_linux.png?resize=741%2C456&ssl=1
[4]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/11/redirecting_command_output_to_file.png?resize=741%2C494&ssl=1
[5]: https://linuxhandbook.com/tee-command/
[6]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/11/display-and-save-linux-command-output.png?resize=741%2C494&ssl=1
[7]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/11/pipe-output-to-file-linux.png?resize=687%2C266&ssl=1
[8]: https://tldp.org/LDP/abs/html/io-redirection.html#FTN.AEN17894

View File

@ -0,0 +1,112 @@
[#]: collector: (lujun9972)
[#]: translator: (Mjseven)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to Save the Output of a Command to a File in Linux Terminal [Beginners Tip])
[#]: via: (https://itsfoss.com/save-command-output-to-file-linux/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
如何将 Linux 终端中命令的输出保存到文件中[新手技巧]
======
当你在 Linux 终端中运行命令或脚本时,它会在终端中打印输出方便你立即查看。
有时你需要将输出保存到文件中以备将来参考。现在,[你当然可以在 Linux 终端中复制和粘贴][1],但是有更好的方法可以在 Linux 命令行中保存 shell 脚本或命令的输出,让我演示给你看。
### 方法 1使用重定向将命令输出保存到文件中
你可以[在 Linux 中使用重定向来达成目的][2]。使用重定向操作符,它会将输出保存到文件中而不是在屏幕上显示。
* &gt; 会将命令输出重定向到文件,它会替换文件中的所有内容。
* &gt;&gt; 会将命令输出添加到文件现有内容的末尾。
使用 STDOUT 重定向运算符 &gt; 将输出重定向到文件:
```
command > file.txt
```
如果 file.txt 不存在,它会自动创建。如果你使用 &gt; 再次重定向到相同的文件,文件内容将被替换为新的输出。
下面的示例将更好地演示它。它首先会保存 _ls -l_ 命令的输出,然后,它将用 _ls *.c_ 命令的输出替换文件的内容。
![将命令输出重定向到文件][3]
如果你不想在保存脚本或命令的输出时丢失现有文件的内容,可以使用 &gt;&gt;
```
command >> file.txt
```
下面这个例子更好地展示了它:
![将命令输出重定向到文件][4]
即使文件不存在,它也会自动创建。
温馨提示:将 Linux 命令输出和错误保存到一个文件中。
如果Linux 命令返回错误,那么错误不会保存在文件中。你可以使用 2&gt;&amp;1 将命令的输出和错误保存到同一个文件中,如下所示:
**command &gt; file.txt 2&gt;&amp;1**
通常0 代表标准输入1 代表标准输出2 代表标准错误。在这里,你要将标准错误(2) 重定向(&)到与标准输出(1) 相同的地址。
### 方法 2使用 tee 命令显示输出并将其保存到文件中
顺便说一句,你是否注意到,当你将命令输出发送到一个文件时,你再也无法在终端上看到它了?[Linux 的 tee 命令][5]解决了这个问题。
类似于将水流发送到两个方向的三通管tee 命令将输出发送到终端以及文件(或作为另一个命令的输入)。你可以像这样使用它:
```
command | tee file.txt
```
同样,如果该文件不存在,它将自动创建。
你还可以使用 tee 命令在附加模式下使用选项 -a
```
command | tee -a file.txt
```
让我用一些简单的例子来演示:
![][6]
我在例子中使用了简单的 Linux 命令。但是请放心,你也可以使用这些方法来保存 bash 脚本的输出。
### 注意:将命令输出保存到文件时,避免管道陷阱
你可能对管道重定向很熟悉,可以使用它来组合 Linux 命令,但不能将输出通过管道传输到文件,它显示找不到 output.txt 命令:
![][7]
这是因为管道将一个命令的输出重定向到另一个命令的输入。在本例中,你向它传递一个了一个文件名而它期望一个命令。
如果你是一个 Linux 命令行新手,我希望这个快速教程对你的 Linux 知识有所帮助。[I/O 重定向][8]是一个需要注意的基本概念。
一如既往,欢迎提出问题和建议。
--------------------------------------------------------------------------------
via: https://itsfoss.com/save-command-output-to-file-linux/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[MjSeven](https://github.com/MjSeven)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://itsfoss.com/copy-paste-linux-terminal/
[2]: https://linuxhandbook.com/redirection-linux/
[3]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/11/redirecting_command_output_to_file_in_linux.png?resize=741%2C456&ssl=1
[4]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/11/redirecting_command_output_to_file.png?resize=741%2C494&ssl=1
[5]: https://linuxhandbook.com/tee-command/
[6]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/11/display-and-save-linux-command-output.png?resize=741%2C494&ssl=1
[7]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/11/pipe-output-to-file-linux.png?resize=687%2C266&ssl=1
[8]: https://tldp.org/LDP/abs/html/io-redirection.html#FTN.AEN17894

View File

@ -1,102 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Keep track of multiple Git remote repositories)
[#]: via: (https://opensource.com/article/20/11/multiple-git-repositories)
[#]: author: (Peter Portante https://opensource.com/users/portante)
跟踪多个 Git 远程仓库
======
拥有一致的命名标准是保持本地和上游 Git 仓库保持直线的关键。
![Digital hand surrounding by objects, bike, light bulb, graphs][1]
当本地 Git 仓库的名称与远程仓库不一致时,与远程仓库协作就会变得很混乱。
解决此问题的一个方法是标准化两个词的使用和含义:`origin` 指的是你个人的 `example.com/<USER>/*` 仓库,而 `upstream` 指的是你从 `origin` 仓库分叉出来的 `example.com` 仓库。换句话说,`upstream` 指的是公开提交工作的上游仓库,而 `origin` 指的是你在上游仓库的本地分叉,例如,你从那里生成拉取请求 PR
以 [pbench][2] 仓库为例,下面是一个逐步建立新的本地克隆的方法,其中 `origin``upstream` 的定义是一致的。
1. 在大多数 Git 托管服务上,当你想在上面工作时,必须对它进行分叉。当你运行自己的 Git 服务器时,这并不是必要的,但对于一个公开的代码库来说,这是一个在贡献者之间传输差异的简单方法。
创建一个 Git 仓库的分叉。在这个例子中,假设你的分叉位于 `example.com/<USER>/pbench`
2. 接下来,你必须获得一个统一资源标识符 [URI][3]),以便通过 SSH 进行克隆。在大多数 Git 托管服务上,比如 GitLab 或 GitHub它在一个标有 **Clone****Clone over SSH** 的按钮或面板上。将克隆 URI 复制到剪贴板中。
3. 在你的开发系统中,使用你复制的文本克隆仓库:
```
`$ git clone git@example.com:<USER>/pbench.git`
```
这将克隆 Git 仓库,默认名称为 `origin`,作为 pbench 仓库的分叉副本。
4. 切换到刚才克隆的目录:
```
`$ cd ~/pbench`
```
5. 下一步,获取源码仓库的 SSH URI你最初分叉的那个。这可能和上面的方法一样。找到 **Clone** 按钮或面板,复制克隆地址。在软件开发中,这通常被称为“上游”,因为(理论上)这是大多数提交发生的地方,而你打算让这些提交流向下游的仓库。
6. 将 URI 添加到你的本地仓库中。是的将有_两个不同_的远程分配给你的本地仓库副本
```
`$ git remote add upstream \ git@example.com:bigproject/pbench.git`
```
7. 现在你有两个命名远程仓库:`origin` 和 `upstream`。 你可以用远程子命令查看你的远程仓库:
```
`$ git remote -v`
```
现在,你的本地 `master` 分支正在跟踪 `origin` master这不一定是你想要的。你可能想跟踪这个分支的 `upstream` 版本,因为大多数开发都在上游进行。 这个想法是,你要在从上游获得的内容的基础上添加更改。
8. 将你的本地的 master 分支改成跟踪 `upstream/master`
```
$ git fetch upstream
$ git branch --set-upstream-to=upstream/master master
```
你可以对任何你想要的分支这样做,而不仅仅是 `master`。例如,有些项目使用 `dev` 分支来处理所有不稳定的变化,而将 `master` 保留给已批准发布的代码。
9. 一旦你设置了你的跟踪分支,一定要 `rebase` 你的 master 分支,使它与上游仓库的任何新变化保持一致:
```
$ git remote update
$ git checkout master
$ git rebase
```
这是一个保持 Git 仓库在不同分叉之间同步的好方法。如果你想自动完成这项工作,请阅读 Seth Kenlon 关于[使用 Ansible 托管 Git 仓库][4]的文章。
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/11/multiple-git-repositories
作者:[Peter Portante][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/portante
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/rh_003588_01_rd3os.combacktoschoolseriesk12_rh_021x_0.png?itok=fvorN0e- (Digital hand surrounding by objects, bike, light bulb, graphs)
[2]: https://github.com/distributed-system-analysis/pbench
[3]: https://en.wikipedia.org/wiki/Uniform_Resource_Identifier
[4]: https://opensource.com/article/19/11/how-host-github-gitlab-ansible