500元制作网站,个人网页设计作品集,wordpress中的页面,enfold wordpress前言
那么这里博主先安利一些干货满满的专栏了#xff01;
首先是博主的高质量博客的汇总#xff0c;这个专栏里面的博客#xff0c;都是博主最最用心写的一部分#xff0c;干货满满#xff0c;希望对大家有帮助。
高质量博客汇总
然后就是博主最近最花时间的一个专栏…前言
那么这里博主先安利一些干货满满的专栏了
首先是博主的高质量博客的汇总这个专栏里面的博客都是博主最最用心写的一部分干货满满希望对大家有帮助。
高质量博客汇总
然后就是博主最近最花时间的一个专栏《Git企业开发控制理论和实操》希望大家多多关注
Git企业开发控制理论和实操 Git的远程操作
博主使用码云Gitee进行讲解操作方法和Github完全一样。
理解分布式版本控制系统
我们目前所说的所有内容(工作区暂存区版本库等等)都是在本地!也就是在你的笔记本或者计算机上。而我们的 Git 其实是分布式版本控制系统什么意思呢? 可以简单理解为我们每个人的电脑上都是一个完整的版本库这样你工作的时候就不需要联网了因为版本库就在你自己的电脑上。既然每个人电脑上都有一个完整的版本库那多个人如何协作呢?比方说你在自己电脑上改了文件A你的同事也在他的电脑上改了文件A这时你们俩之间只需把各自的修改推送给对方就可以互相看到对方的修改了。 分布式版本控制系统通常也有一台充当“中央服务器”的电脑但这个服务器的作用仅仅是用来方便“交换”大家的修改没有它大家也一样干活只是交换修改不方便而已。有了这个“中央服务器”的电脑这样就不怕本地出现问题导致文件丢失了。
中央仓库我们叫“远程仓库”有个很牛的网站叫做Github就是中央仓库的一个作用
当然我这篇文章的读者可能有部分伙伴访问国外网站比较慢这里博主会用国内的一个替代网站叫做码云来进行演示。
创建远程仓库
在Gitee上新建仓库 简单理解issues和pull request Gitee这个平台为我们提供了四种管理者的身份。
远程仓库是由自己的成员的。
这个issues就是一些有问题的人和仓库成员交流的一个地方。
pull request是什么呢
首先对于开发者来说肯定不是在master上进行开发的我们可能是在dev分支上开发然后我们就要进行merge操作。
当然我们知道merge操作是有风险的。因此我们不能随随便便让人来merge。
因此想要进行merge的开发人就要写一个PR(pull request)可以理解成“合并申请单”让仓库管理人看。
管理员同意后我们才能进行merge操作。 克隆远程仓库 这些都是Gitee给我们提供的数据传输协议常用的就是https和ssh。
HTTPS协议clone 使用这里给的网址复制然后使用 git clone 命令。
git clone https://gitee.com/Yufch/remote-gitcode.git注意不能在任何本地仓库下执行这个命令。 这个就是远程仓库下有的东西了。用法和之前讲的完全一样。
git remote -v # 查看远程仓库的一些信息(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$ git remote -v
origin https://gitee.com/Yufch/remote-gitcode.git (fetch)
origin https://gitee.com/Yufch/remote-gitcode.git (push)
(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$ 表示我们是有远程仓库的fetch权限拉权限和push权限推权限。
SSH协议clone
ssh协议是采用一个公钥加密和公钥登陆的一个机制。所以我们必须要把自己本地服务器的一个公钥放到git服务器上进行管理。
我们现在还没有配置公钥。
**第一步创建SSH Key。**在用户主目录下看看有没有.ssh目录如果有再看看这个目录下有没有id_rsa 和 id_rsa.pub 这两个文件如果已经有了可直接跳到下一步。如果没有需要创建SSH Key。
ls -al ~ | grep .ssh # 可以搜索一下~下有没有.ssh文件夹如果没有就要创建SSH Key这个命令就是系统的知识了这里不过多讲解。
设置ssh公钥需要配置邮箱然后这个邮箱要和码云上的一致。这里可以看。 然后配置SSH公钥命令如下。
ssh-keygen -t rsa -C xxx.com(base) [yufcALiCentos7:~]$ ssh-keygen -t rsa -C yufc779gmail.com
Generating public/private rsa key pair.
Enter file in which to save the key (/home/yufc/.ssh/id_rsa):
Created directory /home/yufc/.ssh.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/yufc/.ssh/id_rsa.
Your public key has been saved in /home/yufc/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:1PWuf6UgtkssYGh2x5QasdfaSrD4YmS7EL0Yf7VamusiQ yufc779gmail.com
The keys randomart image is:
---[RSA 2048]----
| ... . |
| . . o . . |
|..o o o * . . |
| .o o * . |
|oo B * S . |
|o. B o .o .. .|
|E.. . o ..oo.. ..|
| o. . o. .. .|
| .o. .. .. |
----[SHA256]-----
(base) [yufcALiCentos7:~]$ 后面的东西全部默认回车即可。
(base) [yufcALiCentos7:~/.ssh]$ cat id_rsa.pub
ssh-rsa AAAAB3NzaasdasdfadSMIpxADoRltTaMiJadsfasdflBld/qF7EHqKwJY4CMhb65A6tsvGPxAPAeYNgufjc4LC5r0v2hdgs0Pk86XIX7vUK6DUrpe6LPTBOdAGTsWmSbcynpJhX97mdM0P2p/3HK0KYmlymyAIzPpEyNF5YRF9goDzI6OBw7Y9WZlp0QWPyWRbnSMOe4olXKY7EFcon5uCrlD3vJNac/3ZIZpKy2TrtvPvcm1fk9sJW5JlcC7P6DByL0CG8ohxGwz2/4l yufc779gmail.com
(base) [yufcALiCentos7:~/.ssh]$这个东西就是你的公钥。弄到码云上即可。
此时就可以clone了。
git clone gitgitee.com:Yufch/remote-gitcode.git向远程仓库推送
准备操作
本地仓库要进行一次push操作将本地某个分支的内容推送到远程仓库中某个分支上。
然后别忘了进去remote-gitcode仓库之后要配置一下name和email。这个要和码云上的一致。
(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$ git config -l
sendpack.sidebanfalse
core.repositoryformatversion0
core.filemodetrue
core.barefalse
core.logallrefupdatestrue
remote.origin.urlgitgitee.com:Yufch/remote-gitcode.git
remote.origin.fetchrefs/heads/*:refs/remotes/origin/*
branch.master.remoteorigin
branch.master.mergerefs/heads/master
(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$ git config user.name Yufch
(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$ git config user.email yufc779gmail.com
(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$ git -l # 这里打错了 ...
Unknown option: -l
usage: git [--version] [--help] [-c namevalue][--exec-path[path]] [--html-path] [--man-path] [--info-path][-p|--paginate|--no-pager] [--no-replace-objects] [--bare][--git-dirpath] [--work-treepath] [--namespacename]command [args]
(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$ git config -l
sendpack.sidebanfalse
core.repositoryformatversion0
core.filemodetrue
core.barefalse
core.logallrefupdatestrue
remote.origin.urlgitgitee.com:Yufch/remote-gitcode.git
remote.origin.fetchrefs/heads/*:refs/remotes/origin/*
branch.master.remoteorigin
branch.master.mergerefs/heads/master
user.nameYufch
user.emailyufc779gmail.com
(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$ # 这样就配置好了那么现在我们先创建一个文件。然后把他添加到版本库中先上一章的内容
(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$ ls
README.en.md README.md
(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$ vim file.txt
(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$ cat file.txt
hello gitee
(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$ git add .
(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$ git commit -m create file.txt
[master 7352d02] create file.txt1 file changed, 1 insertion()create mode 100644 file.txt
(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$ git status
# On branch master
# Your branch is ahead of origin/master by 1 commit.
# (use git push to publish your local commits)
#
nothing to commit, working directory clean
(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$git push 命令
git push origin master:master
# origin: 远程仓库的名字一般都叫origin, 使用 git remote 命令可以查看
# 第一个master: 要推送的本地分支
# 第二个master: 要推送到的远程仓库的分支
# 如果冒号左右两边一样可以省略一个
git push origin master此时就可以在远程仓库中看到我们修改的内容了。
拉取远程仓库
如果现在的情况是远程仓库中的代码是领先于本地仓库的可能别人开发然后push上去了我们想在本地看到远程仓库中的内容我们就要进行拉取操作。 假设有人加了一行hello world然后push上去了我们在本地也想看到这一行。
注意在工作中千万不要直接改码云或者github上的代码要改也是拉到本地然后改完去PR。
git pull origin master:master
# origin: 远程仓库的名字一般都叫origin, 使用 git remote 命令可以查看
# 第一个master: 要拉取的远程仓库的分支
# 第二个master: 要拉取到的本地仓库的分支
# 如果冒号左右两边一样可以省略一个
git pull origin master(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$ git pull origin master:master
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From gitee.com:Yufch/remote-gitcode7352d02..8513266 master - master
Warning: fetch updated the current branch head.
Warning: fast-forwarding your working tree from
Warning: commit 7352d02962528eae4ef12d0669a40f4f7cdf35ec.
Already up-to-date.
(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$ 注意拉下来的分支之后会做一个合并的操作所以pull 拉取 merge
忽略特殊文件
在日常开发中我们有些文件不想或者不应该提交到远端比如保存了数据库密码的配置文件那怎么让 Git知道呢? 在 Git 工作区的根目录下创建一个特殊的.gitignore文件然后把要忽略的文件名填进去Git 就会自动忽略这些文件了。不需要从头写.gitignore文件gitee 在创建仓库时就可以为我们生成不过需要我们主动勾选下。 当然我们刚才创建的时候没选我们就自己创建一个就行。
touch .gitignore之类的意思就是让git忽略.so结尾的和.ini结尾的文件。
如下所示按道理来说我们创建了.gitignore,key.so,token.ini文件之后git status会识别到工作区中有三个文件被创建但是如下所示git status只看到.gitignore被创建了。这就是因为我们设置了忽略。
(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$ touch key.so
(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$ touch token.ini
(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$ git status
# On branch master
# Your branch is ahead of origin/master by 1 commit.
# (use git push to publish your local commits)
#
# Untracked files:
# (use git add file... to include in what will be committed)
#
# .gitignore
nothing added to commit but untracked files present (use git add to track)
(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]此时如果git add .刚才那两个被设置过忽略的文件是不会被提交到暂存区的。
但是在这条件下我还是想提交一个key2.so怎么办呢可以使用以下命令。
git add -f key2.so # 强制add但是我们一般不想去破坏 .gitignore文件的规则的所以git还提供给我们一种语法。 这样就可以排出忽略。
然后如果有一天你的.gitignore文件写了很长很长然后你创建一个key3.so你自己都忘记为什么这个被忽略掉了可以通过一个命令查看为什么被忽略。
git check-ignore -v key.so # 查看一个文件为什么被忽略(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$ git check-ignore -v key.so
.gitignore:4:*.so key.so
(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$ 然后我们就能看到是第四行让它被忽略了。
最后我们推送一下远端就能看到这些文件了。
配置命令别名
如果我觉得我经常要使用git status命令但是它太难打了想起个别名git st行吗可以的。不过我们要进行一些配置。
git config --global alias.st status**这个命令的意思就是给status起别名为st。**是否要--global可以自选。
现在git st就能用了。
(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$ git st
# On branch master
nothing to commit, working directory clean
(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$再配一个吧。
我们以前学过这个。
git log --prettyoneline --abbrev-commit起个别名。
git config --global alias.lpa log --prettyoneline --abbrev-commit(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$ git lpa
7393ea0 add .gitignore
8513266 update file.txt.
7352d02 create file.txt
a9af182 Initial commit
(base) [yufcALiCentos7:~/Src/Bit-Courses/GitDevelopment/remote-gitcode]$不建议初学的时候配置建议大家熟悉之后在工作中的时候再去简化。