-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated by rebot, save issue posts into repo :)
- Loading branch information
0 parents
commit 8f5ce91
Showing
189 changed files
with
11,519 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# This is a basic workflow to help you get started with Actions | ||
|
||
name: Trigger Netlify | ||
|
||
# Controls when the workflow will run | ||
on: | ||
issues: | ||
types: [opened,edited,deleted,transferred,pinned,unpinned,closed,reopened,assigned,unassigned,labeled,unlabeled,locked,unlocked,milestoned,demilestoned] | ||
|
||
jobs: | ||
start: | ||
name: trigger webhook | ||
if: ${{ !github.event.issue.pull_request }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: | | ||
curl -X POST -d {} https://api.netlify.com/build_hooks/5db8f7db6051f5b810798d74 -vvv | ||
env: | ||
NUMBER: ${{ github.event.issue.number }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
嗨嗨嗨 | ||
|
||
这是由机器人自动生成的issue存档😜 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
--- | ||
title: 如何优雅地使用Git合并多个commits? | ||
date: 2019-09-13 | ||
updated: 2019-10-31 | ||
issueid: 10 | ||
tags: | ||
--- | ||
你可能有过下面的经历 | ||
|
||
自己在本地开发,由于 `Github` 配置了CI,所以需要将新的代码 push到 github 来测试 | ||
|
||
所以你的 `commit` 上会有大量无用的 `commit` 与 `commit message` | ||
|
||
比如: | ||
update, done, fix,update,update ... | ||
|
||
当你测试通过之后,你想把上面的 `commit` 合并成一个显示。 | ||
|
||
如果这是你自己的仓库还好,如果是 fork 的仓库,在开发完成之后你想要 pull request,留着那么多的 commits 肯定不合适 | ||
|
||
**那如何将多个 `commits` 记录合并成一个 `commit` 并且保留 `commit` 的代码呢?** | ||
|
||
先创建几个 `commit` 记录 | ||
|
||
``` | ||
mkdir test | ||
cd test | ||
git init | ||
echo 0 > a.md | ||
git add . | ||
git commit -m "add 0" | ||
echo 1 >> a.md | ||
git add . | ||
git commit -m "add 1" | ||
echo 2 >> a.md | ||
git add . | ||
git commit -m "add 2" | ||
echo 3 >> a.md | ||
git add . | ||
git commit -m "add 3" | ||
``` | ||
|
||
现在我们看一下 `commit` 记录 | ||
|
||
``` | ||
git log | ||
``` | ||
|
||
``` | ||
commit 338fe65506a59f02e79badce0ff2c4dd77f08f8c (HEAD -> master) | ||
Author: iamwwc <**@gmail.com> | ||
Date: Thu Sep 12 22:57:19 2019 +0800 | ||
add 3 | ||
commit e693fb400991d69005caa026b4f0f2fc8dbce5a8 | ||
Author: iamwwc <**@gmail.com> | ||
Date: Thu Sep 12 22:57:19 2019 +0800 | ||
add 2 | ||
commit 278713a3b6eb0e5b72670f007bdbc3bb0a1f9aa1 | ||
Author: iamwwc <**@gmail.com> | ||
Date: Thu Sep 12 22:57:19 2019 +0800 | ||
add 1 | ||
commit 3011974bb76dbc5ccc75abf9a528605c60cbb51f | ||
Author: iamwwc <**@gmail.com> | ||
Date: Thu Sep 12 22:57:18 2019 +0800 | ||
add 0 | ||
``` | ||
|
||
你现在想把 `add3`, `add2` 合并到 `add1` 并且保留全部的内容,并将这个新的commit的记录改写为 `add1,2,3` | ||
|
||
有如下两种方式 | ||
|
||
#### Git rebase | ||
|
||
``` | ||
git rebase -i HEAD~3 | ||
// -i 是 --interactive,交互式,Git 会打开操作窗口 | ||
// 当然,你也可以 `git rebase -i 3011974bb76dbc5ccc75abf9a528605c60cbb51f` | ||
``` | ||
|
||
这时 `git` 会为你打开 `rebase` 的对话框 | ||
|
||
你会看到如下的内容。 | ||
|
||
``` | ||
pick 278713a add 1 | ||
pick e693fb4 add 2 | ||
pick 338fe65 add 3 | ||
``` | ||
|
||
而对应着,`git rebase` 有如下命令 | ||
|
||
``` | ||
# p, pick = use commit | ||
# r, reword = use commit, but edit the commit message | ||
# e, edit = use commit, but stop for amending | ||
# s, squash = use commit, but meld into previous commit | ||
# f, fixup = like "squash", but discard this commit's log message | ||
# x, exec = run command (the rest of the line) using shell | ||
# d, drop = remove commit | ||
``` | ||
|
||
我们这里使用 `fixup`,丢弃掉 `log message` | ||
|
||
``` | ||
r 278713a add1,2,3 | ||
f e693fb4 add 2 | ||
f 338fe65 add 3 | ||
``` | ||
|
||
关闭对话框之后进入到 `commit message` 的界面,这时填写 `add1,2,3`并关闭 | ||
|
||
再次 `git log` | ||
|
||
``` | ||
commit 74d943e839c96fe256bd3324a6da0a5e6fbeafa1 (HEAD -> master) | ||
Author: iamwwc <**@gmail.com> | ||
Date: Thu Sep 12 22:57:19 2019 +0800 | ||
add1,2,3 | ||
commit 3011974bb76dbc5ccc75abf9a528605c60cbb51f | ||
Author: iamwwc <**@gmail.com> | ||
Date: Thu Sep 12 22:57:18 2019 +0800 | ||
add 0 | ||
``` | ||
|
||
完成修改 :) | ||
|
||
#### Git reset --soft | ||
|
||
`--soft` 保证你的 `commit` 不丢失,内容不会被删除,仅仅移动了 `HEAD` | ||
|
||
我们将 HEAD 移动到 add1 之前(也就是 `add0`) | ||
|
||
``` | ||
git reset --soft 3011974bb76dbc5ccc75abf9a528605c60cbb51f | ||
``` | ||
|
||
使用 `git log`你会发现只剩下 `add0` 的提交 | ||
|
||
下面添加全部的文件 | ||
|
||
``` | ||
git add . | ||
git commit -m "add1,2,3" | ||
``` | ||
|
||
完成 | ||
|
||
之后往 GitHub 提交时由于 `commit` 的变更你会推送失败 | ||
|
||
可以 `force-with-lease` 更新 | ||
``` | ||
git push --force-with-lease | ||
``` | ||
|
||
不推荐使用 `-force` | ||
|
||
比如A,B一起在 `master` 分支开发,B开发完成之后将代码 `push` 到了 `master` | ||
|
||
A在本地 `master` 分支进行了 `rebase` 操作。这时A与 `remote/master` 已经冲突了 | ||
|
||
如果A 使用 `git push --force`,则会覆盖掉 B 推送到 `master` 上的代码 | ||
|
||
`https://stackoverflow.com/a/37460330/7529562` | ||
|
||
参见 | ||
|
||
`https://github.com/Jisuanke/tech-exp/issues/13` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--- | ||
updated: 2019-09-13 | ||
issueid: 11 | ||
tags: | ||
- 算法与数据结构 | ||
- Leetcode | ||
title: 两个链表相加-leetcode2 | ||
date: 2019-09-13 | ||
--- | ||
[原题在这里](https://leetcode.com/problems/add-two-numbers/) | ||
|
||
### 介绍 | ||
|
||
给你两个非空单向链表 `l1, l2`,将链表按照 `个十百千` 的顺序相加。 | ||
|
||
比如 | ||
|
||
``` | ||
输入: (1 -> 2 -> 3) + (4 -> 5 -> 6) | ||
返回: (5 -> 7 -> 9) | ||
``` | ||
|
||
这里最需要注意的是进位。 | ||
|
||
### 实现 | ||
|
||
```java | ||
public ListNode addTwoNumbers(ListNode l1, ListNode l2) { | ||
int carry = 0; | ||
ListNode origin = new ListNode(0), tmp = origin; | ||
|
||
// 遍历最大长度的链表 | ||
while(!(l1 == null && l2 == null && carry == 0)) { | ||
// 如果 l1 或者 l2 为 null,那么值始终为 0 | ||
int v1 = l1 == null ? 0 : l1.val; | ||
int v2 = l2 == null ? 0 : l2.val; | ||
int num = v1 + v2 + carry; | ||
tmp.next = new ListNode(num % 10); | ||
// 确定是否进位 | ||
carry = num / 10; | ||
carry = num / 10; | ||
tmp = tmp.next; | ||
if (l1 != null) l1 = l1.next; | ||
if (l2 != null) l2 = l2.next; | ||
} | ||
return origin.next; | ||
} | ||
``` | ||
|
||
这道题和我原来的思路不同点在于 | ||
|
||
我往往会去遍历最小的链表,然后 `if` 分开处理 | ||
|
||
```java | ||
while(l1 != null && l2 != null) { | ||
|
||
} | ||
|
||
if (l1 == null ){ | ||
|
||
} | ||
if (l2 == null ){ | ||
|
||
} | ||
|
||
``` | ||
|
||
却没有想到遍历最长链表,如果短链表为 `null`,那直接返回0就可以 | ||
|
||
写算法往往带来的是新的思考方式 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
tags: | ||
- 算法与数据结构 | ||
- Leetcode | ||
title: 最长无重复字串-leetcode3 | ||
date: 2019-09-13 | ||
updated: 2019-09-13 | ||
issueid: 12 | ||
--- | ||
题目来自 | ||
|
||
https://leetcode.com/problems/longest-substring-without-repeating-characters/ | ||
|
||
|
||
### 题目描述 | ||
|
||
给你一个字符串s,输出 最长且不重复的字串 的长度 | ||
|
||
比如输入 `tmsmfdut`,因为最长的不重复字串是 `smfdut`,所以输出 `6` | ||
|
||
### 解决方案 | ||
|
||
既然是最大长度,那肯定需要记录 `max`,使用双索引,i用来遍历s, `j` 为不重复字串的起始索引,我们将字符作为 `key`,下标索引作为 `value`作为索引存放到 `hashmap`中。在后面遍历s时,如果字符存在于 `map` 中,那去 当前距离 `i - j + 1` 与 `max` 的最大值。 | ||
|
||
代码如下 | ||
```java | ||
public int lengthOfLongestSubstring(String s) { | ||
// 存放 character 与 下标索引 | ||
HashMap<Character, Integer> map = new HashMap(); | ||
int max = 0; | ||
for (int i = 0, j = 0; i < s.length(); i ++) { | ||
if(map.containsKey(s.charAt(i))) { | ||
j = Math.max(j,map.get(s.charAt(i)) + 1); | ||
} | ||
map.put(s.charAt(i),i); | ||
max = Math.max(max, i - j + 1); | ||
} | ||
return max; | ||
} | ||
``` | ||
|
||
为什么 `j = Math.max(j,map.get(s.charAt(i)) + 1);`中需要 `+1`? | ||
|
||
看下图,这时我们 j 为1,i为3,hashmap中存放着第一个m, | ||
我们通过 `map.get(s.charAt(i))`获得的是m对应的下标1 | ||
|
||
如果 `j` 等于 `1` ,那么会直接与下标为 `3` 的 `m` 重复,所以我们需要 `+1`,将 `j` 指向 `map` 中 `m` 对应的下标索引的后一位,也就是 `s` 对应的 `2` | ||
|
||
![image](https://user-images.githubusercontent.com/24750337/64864439-ae8e9200-d669-11e9-8774-ecec70544a14.png) | ||
|
||
|
Oops, something went wrong.