Skip to content

Commit 6a85486

Browse files
author
oldestcrab
committed
增加.gitignore知识
2 parents 24093d6 + 1a05950 commit 6a85486

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

git/git基础.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
### git学习笔记
22
> [廖雪峰的Git教程](https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000)
33
#### 基础
4-
> 忽略某些文件时,在Git工作区的根目录下创建一个特殊的`.gitignore`文件,`.gitignore`文件本身要放到版本库里,并且可以对.gitignore做版本管理!
4+
55
```git
66
77
git config --global user.name "oldestcrab"
@@ -133,4 +133,38 @@ git tag -d v.10
133133
134134
# 删除一个远程标签
135135
git push origin :refs/tags/v1.0
136+
```
137+
138+
#### 忽略文件
139+
> 忽略某些文件时,在Git工作区的根目录下创建一个特殊的`.gitignore`文件,`.gitignore`文件本身要放到版本库里,并且可以对.gitignore做版本管理!
140+
141+
匹配的规则例如:
142+
```git
143+
#忽略所有 .a 结尾的文件
144+
*.a
145+
146+
#但 lib.a 除外
147+
!lib.a
148+
149+
# 仅仅忽略项目根目录下的 TODO 文件,不包括 subdir/TODO
150+
/TODO
151+
152+
#忽略 build/ 目录下的所有文件
153+
build/
154+
155+
#会忽略 doc/notes.txt 但不包括 doc/server/arch.txt
156+
doc/*.txt
157+
158+
```
159+
160+
.gitignore只能忽略那些原来没有被track的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的。那么解决方法就是先把本地缓存删除(改变成未track状态),然后再提交:
161+
``` git
162+
git rm -r --cached
163+
164+
git add 
165+
166+
git commit -m'update .gitignore'
167+
168+
git push origin master
169+
136170
```

正则表达式/essential.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,11 @@ for result in results:
414414
所以,如果只是获取第一个内容,可以用 search() 方法,当需要提取多个内容时,就可以用 findall() 方法。
415415

416416
### 6. sub()
417+
> re.sub(pattern, repl, string, count=0, flags=0)
418+
419+
re.sub共有五个参数。
420+
> 其中三个必选参数:pattern, repl, string
421+
> 两个可选参数:count, flags
417422
418423
正则表达式除了提取信息,我们有时候还需要借助于它来修改文本,比如我们想要把一串文本中的所有数字都去掉,如果我们只用字符串的 replace() 方法那就太繁琐了,在这里我们就可以借助于 sub() 方法。
419424

@@ -488,6 +493,32 @@ for result in results:
488493
```
489494
可以看到 a 节点在经过 sub() 方法处理后都没有了,然后再 findall() 直接提取即可。所以在适当的时候我们可以借助于 sub() 方法做一些相应处理可以事半功倍。
490495

496+
### 6.1 sub进阶repl参数
497+
> repl,就是replacement,替换的字符串的意思,repl可以是字符串,也可以是函数。
498+
499+
用法如下:
500+
```python
501+
import re
502+
pattern = re.compile('<img src="(.*?)"', re.S)
503+
a = '''
504+
<img src="/upload/news/images/2018/6/2019331460.jpg">
505+
<img src="/upload/news/images/2018/6/20186211359331460.jpg">
506+
'''
507+
def test(matchobj):
508+
#print(type(matchobj.group()))
509+
#print('matchobj.group(1):\t' + matchobj.group(1))
510+
pattern = re.compile('[a-zA-Z/.]')
511+
c = pattern.sub('', matchobj.group(1))
512+
d = '<img src="./img/' + c + '.jpg"'
513+
#print('d:\t' + d)
514+
return d
515+
b = pattern.sub(test, a)
516+
print(b)
517+
518+
#print(b.group(1))
519+
#print(b)
520+
```
521+
491522
### 7. compile()
492523

493524
前面我们所讲的方法都是用来处理字符串的方法,最后再介绍一个 compile() 方法,这个方法可以讲正则字符串编译成正则表达式对象,以便于在后面的匹配中复用。

0 commit comments

Comments
 (0)