git 和 linux、_linux和git拔掉

git 和 linux、

Let’s face it. We’ve all faced mild criticism from our colleagues for being a “Non-Linux” user or for not using the command line, whether it be in the college or at our place of work :’). Some of us have become so used to the Windows OS that we fear the transition, as just the thought of remembering the Linux commands gives us chills or the sight of a blinking cursor makes us feel uneasy.

L等我们面对现实吧。 无论是在大学还是在我们的工作场所,我们所有人都因成为“非Linux”用户或不使用命令行而受到同事的温和批评。 我们中的某些人已经习惯了Windows操作系统,以至于我们害怕过渡,就像记住Linux命令的想法让我们感到不寒而栗,或者看到闪烁的光标使我们感到不安。

Why should I switch to Linux when I’m happy with the good old Windows OS? — You may think. Well…

当我对旧的Windows OS感到满意时,为什么应该切换到Linux? —你可能会想。

How about the annoying and scary blue screen of death!?

令人讨厌的可怕蓝屏死机呢?

Image Source: Pinterest 图片来源:Pinterest

Not a good enough reason yet? Okay; I’m going to present some reasons that will help you with making your choice and may lead you to consider switching whether you’re a developer or not.

还不够好吗? 好的; 我将提出一些理由,这些理由将有助于您做出选择,并且可能使您考虑是否要选择开发人员。

  • Linux is Open Source — Linux is released under an open-source license, which prevents restrictions on the use of the software, anyone can run, study, modify, and redistribute the source code, or even sell copies of their modified code, as long as they do so under the same license. And you’re probably thinking you’ve never paid a dime for an OS. You have. When you purchase a laptop or desktop, the cost of Windows is included and many of its applications have an associated cost too.

    Linux是开放源代码— Linux是在开放源代码许可下发行的,它可以防止对软件使用的限制,任何人都可以运行,学习,修改和重新分发源代码,甚至出售其修改后的代码的副本,因为他们在相同的许可下这样做。 而且您可能以为您从未为操作系统付出过一毛钱。 你有。 当您购买笔记本电脑或台式机时,Windows的成本也包括在内,其许多应用程序也有相应的成本。

  • Linux doesn't get in your way — Windows is full of bloatware and begs for attention. It’s like the kid in school who desperately wants to be noticed and is borderline belligerent about it. “What would you like me to do,” cries Cortana. “Hi, please make Microsoft Edge your default browser. It is totally better than Chrome” insists the Edge browser. “Help us to help you! We can’t sign in to your Microsoft account!”. “Windows update is ready. Restart now!”. *Ignores*. A few seconds later, “Restart right now!”

    Linux不会妨碍您-Windows充满了膨胀软件,并引起了人们的注意。 就像是一个在学校里的小孩子拼命想要被别人注意并且对这件事border之以鼻。 “你想让我做什么,” Cortana喊道。 “嗨,请将Microsoft Edge设置为默认浏览器。 它完全比Chrome更好” ,Edge浏览器坚称。 “帮助我们为您提供帮助! 我们无法登录您的Microsoft帐户!”。 “ Windows更新已准备就绪。 现在重启!”。 *忽略*。 几秒钟后, “立即重新启动!”

  • Skill Development for Industry— For people studying to become computer professionals, having Linux skills is already highly desirable, and it could, in fact, eventually become virtually mandatory. With regard to careers, it is becoming increasingly valuable to have Linux skills rather than just knowing how to use Microsoft Windows. This is because the role of Linux will continue to expand — and many industry experts expect it to become the dominant operating system for some, or most, types of applications. Moreover, Linux skills are becoming increasingly important for many other fields as well, ranging from business to biotechnology to industrial design.

    行业技能开发-对于学习成为计算机专业人员的人们来说,拥有Linux技能已经是非常可取的,实际上,它最终可能实际上成为强制性的。 关于职业,拥有Linux技能而不是仅仅知道如何使用Microsoft Windows变得越来越有价值。 这是因为Linux的作用将继续扩大-许多行业专家期望Linux成为某些或大多数类型的应用程序的主要操作系统。 而且,Linux技能对于从商业到生物技术再到工业设计的许多其他领域也变得越来越重要。

  • Linux is ideal for the Public Cloud — Due to its modularity, power efficiency, reliability, scalability to support critical workloads, security efficiency, Linux has become the natural technology for cloud computing. Having all these strengths as an operating system, it has a great influence on the market. All the major public cloud providers Amazon Web Services (AWS) to Microsoft Azure and Google Cloud Platform (GCP) use different versions of Linux.

    Linux是公共云的理想选择-由于其模块化,能效,可靠性,可支持关键工作负载的可扩展性,安全性,Linux已成为云计算的自然技术。 具有所有这些优点作为操作系统,它对市场有很大的影响。 Microsoft AzureGoogle Cloud Platform (GCP)的所有主要公共云提供商Amazon Web Services (AWS)都使用不同版本的Linux。

Hmm… That sounds really convincing, doesn’t it?! Well, if you’re down for it, let’s get started with some basics of Linux.

嗯……听起来真令人信服,不是吗? 好吧,如果您不愿意这样做,让我们开始学习Linux的一些基础知识。

Linux基础 (Linux Basics)

Let’s get started by hopping onto a Linux system. Here are some ways to begin:

让我们开始跳到Linux系统上。 这是一些开始的方法:

  • Set up WSL (Windows Subsystem for Linux)

    设置WSL (Linux的Windows子系统)

  • Use Gitpod

    使用Gitpod

  • Install a Linux (Ubuntu 20.04) Virtual Machine

    安装Linux(Ubuntu 20.04)虚拟机

术语警报!!!(Terminology Alert!!!)

  • Root — The basic word used mostly everywhere. root is the parent folder of any Linux. It contains different folders such as usr, bin, mnt folders for containing different types of files, software, and user data. The root user has the superuser permissions and he can do any changes or modifications to files and permissions.

    根-基本词几乎在所有地方都使用。 root是任何Linux的父文件夹。 它包含不同的文件夹,例如usr,bin,mnt文件夹,用于包含不同类型的文件,软件和用户数据。 超级用户具有超级用户权限,他可以对文件和权限进行任何更改或修改。

  • Sudo grants superpowers of a hero. In Linux, sudo is used for executing commands as superuser when you are logged in as any user. Sudo is created such as to take care of accidentally changing the core files. Sudo makes sure that core files are not accessed or changed by a user, changing may unstabilize or break OS. You need to use it wisely.

    须藤助学金 英雄的超级大国。 在Linux中,当您以任何用户身份登录时,sudo用于以超级用户身份执行命令。 创建Sudo的目的是为了意外更改核心文件。 Sudo确保用户不会访问或更改核心文件,更改可能会不稳定或破坏操作系统。 您需要明智地使用它。

git 和 linux、_linux和git拔掉_第1张图片
Image Source: Google Images 图片来源:Google图片
  • Absolute/Relative Pathnames — Directories are arranged in a hierarchy with root (/) at the top. The position of any file within the hierarchy is described by its pathname. Elements of a pathname are separated by a /. A pathname is absolute, if it is described in relation to root, thus absolute pathnames always begin with a /.

    绝对/相对路径名-目录按层次结构排列,根( / )位于顶部。 层次结构中任何文件的位置均由其路径名描述。 路径名的元素由/分隔。 路径名是绝对的(如果相对于root进行了描述),因此绝对路径名始终以/开头。

  • Home Directory — The directory in which you find yourself when you first login is called your home directory. More on Linux directory structure.

    主目录-首次登录时会在其中找到的目录称为主目录。 有关Linux目录结构的更多信息

  • Directories . (dot) and .. (dot dot) — The filename . (dot) represents the current working directory; and the filename .. (dot dot) represents the directory one level above the current working directory, often referred to as the parent directory.

    目录。 (点)和..(点)—文件名 (点)表示当前工作目录; 文件名.. (点号)表示当前工作目录上一级的目录,通常称为父目录。

  • Symbolic link — A symlink is a type of file in Linux that points to another file or a folder on your computer. Symlinks are similar to shortcuts in Windows.

    符号链接—符号链接是Linux中的一种文件,指向您计算机上的另一个文件或文件夹。 符号链接类似于Windows中的快捷方式。

现在您已经准备好,这里是常用Linux命令的概述 (Now that you’re ready, here’s an overview of commonly used Linux Commands)

  • man is your best friend when you are wondering what a command does and how to use it.

    当您想知道命令的功能以及如何使用它时, man 是您最好的朋友。

  • echo prints a text of line provided to it.

    echo打印提供给它的一行文本。

  • pwd is to find out the path of the current working directory (folder) you’re in. The command will return an absolute path.

    pwd用于查找您所在的当前工作目录(文件夹)的路径。该命令将返回绝对路径。

  • cdhelps navigate through Linux files and directories as cd . You can go to your home dir anytime using (cd ~ or cd), where ~ indicates the home dir. To go to your last dir, you can use (cd -). To go the parent dir of the current dir, use (cd..).

    cd帮助 cd 导航Linux文件和目录。 您可以使用( cd〜cd )随时转到主目录,其中〜表示主目录。 要转到最后一个目录,可以使用( cd- )。 要转到当前目录的父目录,请使用( cd .. )。

  • lshelps to view the contents of a dir (ls ). By default, this command will display the contents of your current working dir. You can also add flags. Wondering which flags to use!? Remember your best buddy ‘man’. Try out ls -a, ls -R and ls -al. What do you observe?

    ls帮助查看目录的内容( ls )。 默认情况下,此命令将显示当前工作目录的内容。 您还可以添加标志。 想知道使用哪些标志!? 记住你最好的哥们。 试用ls -a,ls -R和ls -al。 你观察到什么?

  • mkdir is used to create directories. You can specify the -p option to the mkdir command to create a parent directory.

    mkdir 用于创建目录。 您可以在mkdir命令中指定-p选项以创建父目录。

  • touch is used to create files.

    touch 用于创建文件。

  • rmdir is used to delete a directory. However, rmdir only allows you to delete empty directories.

    rmdir 用于删除目录。 但是, rmdir仅允许您删除空目录

  • rm is used to delete directories and the contents within them. If you only want to delete the directory — as an alternative to rmdir — use rm -r.

    rm 用于删除目录及其中的内容。 如果只想删除目录(作为rmdir的替代方法),请使用rm -r

☣危险Z (☣HAZARD)

Any idea what happens when you give ‘sudo rm -rf *’? — It is the code that deletes everything on the computer. rm means to remove, -rf flag deletes the entire folder forcefully. * stands for every file/folder on the Linux system.

知道使用“ sudo rm -rf *”会发生什么? 它是删除计算机上所有内容的代码。 rm表示要删除,-rf标志强制删除整个文件夹。 *表示Linux系统上的每个文件/文件夹。

git 和 linux、_linux和git拔掉_第2张图片
Image Source: Reddit 图片来源:Reddit
  • cp is used for copying files and directories from one location to another.

    cp 用于将文件和目录从一个位置复制到另一位置。

  • mv is used to rename files or directories. It also moves a file or directory to another location in the directory structure.

    mv 用于重命名文件或目录。 还将文件或目录移动到目录结构中的另一个位置。

git 和 linux、_linux和git拔掉_第3张图片
Image Source: Google Images 图片来源:Google图片
  • chmod [reference][operator][mode]file...is used to change the access mode of a file. With the chmod, User U, Groups G, and Others O can be granted varying permissions such as Read, Write or Execute to files and directories. Read has a value of 4, Write of 2, Execute of 1. Add the values of required permissions and assign them in the corresponding position for UGO. More on file permissions.

    chmod [reference][operator][mode]file...用于更改文件的访问模式。 使用chmod,可以向用户U 组G其他O授予不同的权限,例如对文件和目录的读取,写入或执行。 Read的值为4,Write的值为2,Execute的值为1 。 添加所需权限的值,并将其分配给UGO的相应位置。 有关文件权限的更多信息。

  • grep [options] pattern [files]filter searches a file for a particular pattern of characters, and displays all lines that contain that pattern. Options and files args are optional. Some of the options description:

    grep [options] pattern [files]过滤器在文件中搜索特定字符模式,并显示包含该模式的所有行。 选项和文件args是可选的。 一些选项说明:

    grep [options] pattern [files]filter searches a file for a particular pattern of characters, and displays all lines that contain that pattern. Options and files args are optional. Some of the options description:-c: This prints only a count of the lines that match a pattern

    grep [options] pattern [files]过滤器在文件中搜索特定字符模式,并显示包含该模式的所有行。 选项和文件args是可选的。 一些选项描述: -c :这仅打印与模式匹配的行数

    grep [options] pattern [files]filter searches a file for a particular pattern of characters, and displays all lines that contain that pattern. Options and files args are optional. Some of the options description:-c: This prints only a count of the lines that match a pattern-i: Ignores, the case for matching

    grep [options] pattern [files]过滤器在文件中搜索特定字符模式,并显示包含该模式的所有行。 选项和文件args是可选的。 一些选项描述: -c :仅打印与模式匹配的行数-i:忽略匹配的大小写

    grep [options] pattern [files]filter searches a file for a particular pattern of characters, and displays all lines that contain that pattern. Options and files args are optional. Some of the options description:-c: This prints only a count of the lines that match a pattern-i: Ignores, the case for matching-l: Displays a list of filenames only.

    grep [options] pattern [files]过滤器在文件中搜索特定字符模式,并显示包含该模式的所有行。 选项和文件args是可选的。 一些选项说明: -c :仅打印与模式匹配的行数-i:忽略匹配的情况-l:仅显示文件名列表。

    grep [options] pattern [files]filter searches a file for a particular pattern of characters, and displays all lines that contain that pattern. Options and files args are optional. Some of the options description:-c: This prints only a count of the lines that match a pattern-i: Ignores, the case for matching-l: Displays a list of filenames only.-n: Display the matched lines and their line numbers.

    grep [options] pattern [files]过滤器在文件中搜索特定字符模式,并显示包含该模式的所有行。 选项和文件args是可选的。 一些选项说明: -c :仅打印与模式匹配的行数-i:忽略匹配的情况-l:仅显示文件名列表。 -n:显示匹配的行及其行号。

Linux中的输入输出重定向 (Input-Output Redirection in Linux)

  1. Overwrite

    覆写

  • ”>” standard output; So whatever you will write after running this command, all will be redirected and copied to the “file.txt”. This is standard output redirection.

    ”>”标准输出; 因此,无论您在运行此命令后要编写什么内容,都将被重定向并复制到“ file.txt”中。 这是标准输出重定向。

cat > file.txt
First time: Check your file after typing this in the terminal
cat > file.txt
Second time: Check your file after typing this in the terminal
  • ”<” standard input is to copy the input and give the output to the screen.

    ”<”标准输入是复制输入并将输出提供给屏幕。

cat < file.txt

2. Append

2.追加

  • ”>>” standard output; This is used when we want to append some lines to the existing content of the file.

    ”>>”标准输出; 当我们想要在文件的现有内容中添加一些行时,将使用此方法。

cat >> file.txt
First time: Check your file after typing this in the terminal
cat >> file.txt
Second time: Check your file after typing this in the terminal
  • ”<<” standard input; What could be different with this? Test it out for yourself.

    ”<<”标准输入; 这有什么不同? 自己测试一下。

cat << file.txt

3. Piping is a form of redirection that lets you use two or more commands such that the output of one command serves as input to the next. You can make it do so by using the pipe character ‘|’. Pipes are unidirectional i.e data flows from left to right through the pipeline. Syntax:

3.管道是一种重定向形式,它使您可以使用两个或多个命令,以便一个命令的输出充当下一个命令的输入。 您可以使用竖线字符“ |”来做到这一点。 管道是单向的,即数据通过管道从左到右流动。 语法: command_2 | command_3 | .... | command_N>

Here are some examples for you to try:

以下是一些示例供您尝试:

  • Listing all files and directories and give it as input to more command:

    列出所有文件和目录,并将其作为更多命令的输入:
$ ls -l | more
  • Use head and tail to print lines in a particular range in a file: This will print the last 5 lines from the first 7 lines in the file

    使用头和尾在文件的特定范围内打印行:这将打印文件前7行中的最后5行
$ cat file.txt | head -7 | tail -5

Here are 20 amusing Linux commands to have fun with the terminal:

这是20个有趣的Linux命令,可让您在终端上玩耍:

什么是Cron? (What is Cron?)

The software utility cron is a time-based job scheduler. Cron schedules jobs (commands or shell scripts) to run periodically at fixed times, dates, or intervals. You could set it to download a movie every Friday evening (Write a script to download the latest movie and assign it to cron).

软件实用程序cron是基于时间的作业计划程序。 Cron计划作业(命令或Shell脚本)以固定的时间,日期或间隔定期运行。 您可以将其设置为在每个星期五晚上下载电影(编写脚本以下载最新电影并将其分配给cron)。

需要Bash Shell脚本 (Need for Bash shell scripting)

A shell script is a sequence of commands for which you have a repeated use. This sequence is typically executed by entering the name of the script on the command line. Alternatively, you can use scripts to automate tasks using the cron facility. Here’s a lifesaver for you:

Shell脚本是您可以重复使用的一系列命令。 通常通过在命令行上输入脚本的名称来执行此序列。 另外,您可以使用脚本通过cron工具自动执行任务。 这是您的救星:

Git基础 (Git Basics)

git 和 linux、_linux和git拔掉_第4张图片
Image Source: Google Images 图片来源:Google图片

Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later. So ideally, we can place any file in the computer on version control.

版本控制是一个记录一段时间内对一个文件或一组文件的更改的系统,以便您以后可以调用特定版本。 因此,理想情况下,我们可以将计算机上的任何文件置于版本控制上。

It allows one to revert changes, revert the entire project back to a previous state, review changes, see who last modified something that might be causing a problem, who introduced an issue and when, and more.

它允许人们还原更改,将整个项目还原到以前的状态,查看更改,查看谁最后修改了可能引起问题的东西,谁引入了问题以及何时等等。

So, what is Git?

那么,什么是Git?

Git is a version-control system for tracking changes in computer files and coordinating work on those files among multiple people. A user “clones” a copy of a repository (a collection of files) and has the full history of the project on their own hard drive. This clone has all of the metadata of the original while the original itself is stored on a self-hosted server or a third-party hosting service like GitHub.

Git是一个版本控制系统,用于跟踪计算机文件中的更改并在多人之间协调这些文件上的工作。 用户“克隆”存储库的副本(文件的集合),并在自己的硬盘上拥有项目的完整历史记录。 此克隆具有原始文档的所有元数据,而原始文档本身存储在自托管服务器或诸如GitHub的第三方托管服务

术语警报!!! (Terminology Alert!!!)

git 和 linux、_linux和git拔掉_第5张图片
Image Source: Crio.do 图片来源:Crio.do
  • Working directory contains all the files you see on your project directory.

    工作目录包含您在项目目录上看到的所有文件。

  • Staging index is a file in the Git directory that stores the information about what is going to be included in your next commit.

    暂存索引是Git目录中的一个文件,用于存储有关下次提交中将包含的内容的信息。

  • Master Branch: When a commit is made in a repository it’s added to the branch you’re currently on. By default, a repository has a branch called master. It is useful to create a separate branch that acts as a safe isolated environment from your last commit.

    主分支:在存储库中进行提交时,会将其添加到您当前所在的分支中。 默认情况下,存储库具有一个称为master的分支 创建一个单独的分支作为上次提交时的安全隔离环境很有用。

  • Local repository is the one on which we will make local changes, typically this local repository is on our computer.

    本地存储库是我们将对其进行本地更改的存储库,通常,此本地存储库位于我们的计算机上。

  • Remote repository is stored on a code hosting service like GitHub or on an internal server that all team members use to exchange their changes.

    远程存储库存储在GitHub之类的代码托管服务上,或者存储在所有团队成员用来交换更改的内部服务器上。

生成/检查计算机以获取现有的SSH密钥 (Generate/check your machine for existing SSH keys)

Why you ask? Using the SSH protocol, you can connect and authenticate to remote servers and services. With SSH keys, you can connect to GitHub without supplying your username or password at each visit.

你为什么问? 使用SSH协议,您可以连接远程服务器和服务并进行身份验证。 使用SSH密钥,您可以连接到GitHub,而无需在每次访问时都提供用户名或密码。

  • Learn more about SSH

    进一步了解SSH

  • Check if you have an existing SSH key

    检查您是否已有SSH密钥

  • Generate an SSH key

    生成SSH密钥

  • Add SSH key to your GitHub account

    将SSH密钥添加到您的GitHub帐户

  • Test it’s connection

    测试它的连接

现在您已经准备好,这里是常用的Git命令的概述(Now that you’re ready, here’s an overview of commonly used Git Commands)

Create or Clone a repository

创建或克隆存储库

  • Create a repository from scratch: git init

    从头开始创建存储库: git init

  • Clone an existing repository:git clone ...

    克隆现有存储库: git clone ...

  • Clone repository and use different name:git clone ... new_name

    克隆存储库并使用其他名称: git clone ... new_name

Branch

  • List all branches:git branch

    列出所有分支: git branch

  • Create a new branch:git branch

    创建一个新分支: git branch

  • Delete branch:git branch -d

    删除分支: git branch -d

  • You cannot delete a branch you’re currently on.

    您无法删除当前所在的分支。

  • You cannot delete a branch if it contains any commits that aren’t on any other branch.

    如果分支包含任何不在其他分支上的提交,则不能删除该分支。

  • To force deletion:git branch -D

    强制删除: git branch -D

  • Switch between branches:git checkout

    在分支之间切换: git checkout

View Information

查看信息

  • Determine a Repo’s status:git status

    确定仓库的状态: git status

  • Display a Repo’s commits:git log

    显示仓库的提交: git log

  • Display a Repo’s commits in a compact way:git log --oneline

    以紧凑的方式显示回购的提交: git log --oneline

  • Viewing Modified Files:git log --stat

    查看修改的文件: git log --stat

  • Viewing file changes: git log -p

    查看文件更改: git log -p

Add

“Staging” means moving a file from the Working Directory to the Staging Index.

“登台”是指将文件从工作目录移动到登台索引。

  • Staging Files:git add

    暂存文件: git add

  • Unstaging files:git rm --cached ...

    正在取消暂存文件: git rm --cached ...

  • Stage all the files:git add .

    git add .所有文件: git add .

Commit

承诺

Take files from the Staging Index and save them in the repository.

从暂存索引中获取文件并将其保存在存储库中。

  • Commit staged files (This will open the editor for commit message):git commit

    提交暂存文件(这将打开编辑器以显示提交消息): git commit

  • Commit files without opening the code editor:git commit -m "Commit message"

    提交文件而不打开代码编辑器: git commit -m "Commit message"

  • Undo the changes made in a commit:git revert

    撤消在提交中所做的更改: git revert

  • Reset commit (This will erase commits):git reset

    重置提交(这将删除提交): git reset

Push

  • Sends the recent commit history from your local repository up to GitHub. git push origin

    将最近的提交历史记录从本地存储库发送到GitHubgit push origin

Fetch

  • git fetchThis will download the latest info about the repo from origin (such as all the different branches stored on GitHub). It doesn’t change any of your local files — just updates the tracking data stored in the .git folder.

    git fetch这将下载关于回购从最新的信息origin (如存储在GitHub上所有不同的分支机构)。 它不会更改您的任何本地文件-只是更新存储在.git文件夹中的跟踪数据。

Merging

合并中

  • git merge This will take all commits that exist on the other-branch-name branch and integrate them into your own current branch.

    git merge 这将获取other-branch-name分支上存在的所有提交,并将它们集成到您自己的当前分支中。

Pull

  • git pull origin masterIt grabs any changes from the GitHub repository and merges them into your local repository. As a shortcut, you can use the pull command to both fetch and merge all in one step.

    git pull origin master它从GitHub存储库中获取所有更改,并将它们合并到您的本地存储库中。 作为一种快捷方式,您可以使用pull命令一步来获取合并所有内容。

Diff

差异

  • See changes that have been made but haven’t been committed yet:git diff

    查看已进行但尚未提交的更改: git diff

It seems you’ve mastered the basics of Linux and Git. Here’s a challenge for you to try and a solution for the same.

看来您已经掌握了Linux和Git的基础知识。 这是您要尝试的挑战,而相同的解决方案。

建立自己的Google云端硬盘 (Build your own Google Drive)

git 和 linux、_linux和git拔掉_第6张图片
Image Source: Crio.do 图片来源:Crio.do

With the help of our knowledge on Linux and Git, the task is to simulate the working of Google Drive — backup and sync. Learn more about it over here:

借助我们对Linux和Git的了解,任务是模拟Google Drive的工作-备份和同步 在这里了解更多有关它的信息:

希望您能尝试一下。 这是解决方案 (I hope you made an attempt. Here’s the solution)

Assuming you learned bash scripting, add this bash file to your repository.

假设您学习了bash脚本,请将此bash文件添加到存储库中。

Let’s say your files are located in /home/username/myGoogleDrive and we name the file below /home/username/myGoogleDrive/AUTOUPDATE.

假设您的文件位于/home/username/myGoogleDrive并且在/home/username/myGoogleDrive/AUTOUPDATE下命名该文件。

#!/usr/bin/env bash

cd $(dirname ${BASH_SOURCE[0]})DATE=$(date)if [[ -n $(git status -s) ]]; then
echo "Changes found. Pushing changes..."
git add -A && git commit -m "updated at $DATE " && git push
else
echo "No changes found. Skip pushing."
fi

Then, add a scheduled task, crontab to run this script as frequently as you want your GitHub to be updated.

然后,添加计划任务crontab,以在您希望更新GitHub时频繁运行此脚本。

  • It will check if there are any changes first and only commit and push all changes if there are any changes. Pretty efficient, right!?

    它将首先检查是否有任何更改,并且仅在存在任何更改的情况下才提交并推送所有更改 非常有效,对!!

*/60 * * * * /home/username/myGoogleDrive/AUTOUPDATE
  • This will run the script every 60th minute. Though you can set it as per your requirements.

    这将每60分钟运行一次脚本 虽然您可以根据需要进行设置。

Don’t forget to give this file execute permission with chmod +x /home/username/myGoogleDrive/AUTOUPDATE

不要忘记使用chmod +x /home/username/myGoogleDrive/AUTOUPDATE授予该文件执行权限

  • This will always push the changes with the commit message of “updated with the exact date and time when the changes were committed.

    这将始终以“ updated 提交消息推送更改,并带有更改的确切日期和时间。

Surely, this isn’t the only possible solution. There are several intuitive ways to go about implementing this.

当然,这不是唯一可行的解​​决方案。 有几种直观的方法可以实现此目的。

Do you think it’s possible to implement this without crontab? Here’s a little hint for you:

您是否认为无需crontab即可实现此目标? 给您一些提示:

You’re probably wondering by now how I conquered my fear of the terminal; how I managed to acquire the skills to pen it down in this blog. Well…

您可能现在想知道我如何克服了对终端的恐惧; 我如何在本博客中获得技巧以写下来。 好…

是时候滚下窗帘 (Time to roll down the curtain )

git 和 linux、_linux和git拔掉_第7张图片
Image Source: Crio.do 图片来源:Crio.do

I was a part of the #IBelieveInDoing September Edition 10-Day challenge. It was a great opportunity for me to work on my weak Linux skills and polish them to the point where I was able to share what I learned through my very first medium tech blog.

我参加了#IBelieveInDoing 9月版10天挑战赛。 对于我来说,这是一个很好的机会,可以继续研究我的弱小的Linux技能,并将其提高到可以分享通过我的第一个中等技术博客所学到的知识的程度。

git 和 linux、_linux和git拔掉_第8张图片
Image Source: Crio.do 图片来源:Crio.do

The challenge started off with this fun and interactive kick-off call where we were introduced to a whole bunch of amazing developers and participants. The challenge mainly had 3 parts to it. The first part was to learn the essential developer skills (Linux and Git) through a series of Bytes well presented on Crio.do. The second part was the bonus challenge which revolved around Simulating Google Drive using our knowledge on Linux and Git and the third part is the blog.

挑战始于这个有趣的互动式启动电话,在此我们被介绍给了一大堆了不起的开发人员和参与者。 挑战主要包括三个部分。 第一部分是通过Crio.do上介绍的一系列Bytes学习基本的开发人员技能(Linux和Git)。 第二部分是奖金挑战,它围绕使用我们在Linux和Git上的知识来模拟Google云端硬盘而展开,第三部分是博客。

Thank you to the entire Crio family for a wonderful experience. I had a great time learning and I’m looking forward to more challenges. Kudos to all the amazing participants! :)

感谢整个Crio一家人的美好经历。 我度过了愉快的时光,我期待更多的挑战。 感谢所有了不起的参与者! :)

Cheers,

干杯,

Amit Kumar

阿米特·库玛(Amit Kumar)

翻译自: https://medium.com/@amitk526188/linux-and-git-unplugged-565bb0079785

git 和 linux、

你可能感兴趣的:(git,linux)