美文网首页生物信息数据科学
17.《Bioinformatics-Data-Skills》之

17.《Bioinformatics-Data-Skills》之

作者: DataScience | 来源:发表于2021-06-09 07:25 被阅读0次

Bioinformatics-Data-Skills》之GIT基本操作(2)

前面我们学习了使用Git进行文件track,stage与commit的基本操作,今天学习剩余的基本操作,分别是git diff, git log, git mv & rm , .gitignore, 和git reset

git diff

git diff 用来查看当前版本的文件与已经staged文件的区别(若没有staged文件则展示与上一个版本文件的区别),例如我们在readme文件中加入日期:

echo "Project start $(date +%F)" >> readme.md
git diff
# diff --git a/readme.md b/readme.md
# index a4b8a1b..738a817 100644
# --- a/readme.md
# +++ b/readme.md
# @@ -35,3 +35,4 @@ Recommended trimming programs:
# 
#  - Trimmomatic
#  - Scythe
# +Project start 2021-06-05

可以看到修改后的文件与旧文件在哪一行发生了改变,如果将readme文件进行stage就没有区别了(因为当前文件与stage文件是一致的):

git add readme.md
git diff

git log

使用git log命令可以查看commit历史,commit历史是一个有向无环图(fig.1)。

Figure 1 git commit历史
git log
# commit 31f39cc98be60b1b4131cf0593083116c89ae6f3 (HEAD -> master)
# Author: Liuwei <pseudoway@163.com>
# Date:   Sat Jun 5 16:19:55 2021 +0800
# 
#     初始化

commit 后面的一串字符根据新版文件与旧版文件区别生成的唯一hash值,这里只有一次commit历史(可以自己试着多commit几次看一下历史)。

git mv & git rm

使用git进行版本管理后如果我们继续采用mv或者rm命令移动或删除文件的话会让git困惑,更应该采用git mv等命令。例如我们将readme.md文件重命名为README.md

git mv readme.md README.md
git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
# 
#         renamed:    readme.md -> README.md
# 
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
# 
#         data/seqs/
git commit -m "重命名文件"

可以看到文件名修改已经被追踪并且直接stage(注意:这与文件的内容改变后需要手动stage不同)。

.gitignore

使用git status的时候会展示出所有untracked文件,随着分析的进行存在大量的文件的时候,继续显示大量非追踪文件是一种负担。我们可以创建.gitignore文件来忽视文件的track。例如我们想要忽视size特别大的fastq文件:

echo "data/seqs/*.fastq" >> .gitignore
git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
# 
#         renamed:    readme.md -> README.md
# 
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
# 
#         .gitignore

可以将.gitignore文件也加入track的。

我们可以选择性地忽略以下几种类型的文件:

  1. 原始数据,这些数据size特别大,进行clone的时候会非常缓慢,推荐采用别的方式共享;

  2. 部分中间结果,某些中间结果数据量也非常大而某些重新生成非常容易,这些文件建议忽略;

  3. 编辑器生成的临时文件,例如vim和emac编辑器的临时文件example.txt~#example.txt#

  4. 程序生成的临时文件。

针对某些无论如何都应该忽略的文件(后两种文件,通过通配符来匹配),我们可以在home目录下设定一个全局的忽视文件~/.gitignore_global,所有工程的git配置都可以通过以下命令共享:

git config --global core.excludefile ~/.gitignore_global

git reset

为了实现版本控制的组织性与纪律性,git的每一次commit的版本和版本描述最好是有阶段性意义的。如果我们无意中将一份修改一半的文件进行了stage,可以采用git reset命令来unstage。

echo "TODO: something to do blabla" >> README.md
git add README.md
git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
# 
#         modified:   README.md
# 
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
# 
#         .gitignore
git reset HEAD README.md
# Unstaged changes after reset:
# M       README.md
git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
# 
#         modified:   README.md
# 
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
# 
#         .gitignore
# 
# no changes added to commit (use "git add" and/or "git commit -a")

git reset是根据索引来重新stage的,HEAD参数指的是最近一次staged文件。

相关文章

网友评论

    本文标题:17.《Bioinformatics-Data-Skills》之

    本文链接:https://www.haomeiwen.com/subject/bhfheltx.html