Skip to content

Commit 6e7d386

Browse files
committed
Merge branch 'master' into work
2 parents 09d0d2c + 62cb50b commit 6e7d386

File tree

90 files changed

+4354
-84
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+4354
-84
lines changed

.github/CONTRIBUTING.md

+216-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,216 @@
1-
**Working on your first Pull Request?** You can learn how from this *free* series [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github)
1+
# Contribute to doocs/leetcode project
2+
3+
![hardcore-forking-yanglbme](http://p9ucdlghd.bkt.clouddn.com/hardcore-forking-yanglbme.gif)
4+
5+
由于此前不少小伙伴跑来问我要怎么参与这个项目,他们还没有在 GitHub 上搞过这种团队合作项目,对整个流程不太熟悉。因此,我实际操作了一遍,写下了这个教程,希望可以帮助到那些想要参与进来却不太熟悉操作的小伙伴们,让你们能够快速入门😄~
6+
7+
8+
## 安装并配置 Git
9+
10+
![git](http://p9ucdlghd.bkt.clouddn.com/git-logo-2color-lightbg.png)
11+
12+
首先你需要在自己电脑上安装 Git,对于已经安装过 Git 并配置好相关信息的小伙伴们,这第一步就不用再做啦~
13+
14+
对于 Windows 用户,Git 官网下载链接,[请戳这里](https://git-scm.com/downloads),下载完安装即可。
15+
16+
对于 Linux 用户,只需要执行以下命令即可安装:
17+
```bash
18+
sudo apt-get install git
19+
```
20+
21+
[更多 Git 相关安装指引,需要的戳戳戳😀。](https://help.github.com/articles/set-up-git/)
22+
23+
安装完成之后,
24+
Windows 用户打开 Git Bash 命令行窗口,而 Linux 用户打开 `Terminal` 窗口,进行后续操作。
25+
26+
设置 Git 用户名及邮箱,注意,要与 GitHub 上的用户名及邮箱**保持一致**,此前有小伙伴邮箱没有与 GitHub 帐户邮箱同步,导致后续出现了一点小问题。
27+
28+
在本次演示中,我使用 GitHub 帐户 `igayhub`,邮箱为 `contact@yanglibin.info`。因此,
29+
30+
设置 Git 用户名:
31+
```bash
32+
git config --global user.name "igayhub"
33+
```
34+
35+
设置 Git 邮箱:
36+
```bash
37+
git config --global user.email "contact@yanglibin.info"
38+
```
39+
40+
> 说明:此后的所有演示,都使用 GitHub 帐户 `igayhub`,小伙伴们操作的时候,用自己的帐户跟着演示操作即可。
41+
42+
## Fork 代码仓库
43+
44+
[本代码仓库](https://github.com/doocs/leetcode)中,点击图示中的 `Fork` 按钮。
45+
46+
![fork-doocs-leetcode](http://p9ucdlghd.bkt.clouddn.com/fork-doocs-leetcode.png)
47+
48+
这个操作会将代码仓库复制到你的账户名下,如:`igayhub/leetcode`
49+
50+
![result-of-fork](http://p9ucdlghd.bkt.clouddn.com/result-of-fork.png)
51+
52+
53+
## Clone 代码仓库
54+
将复制后的代码仓库克隆到你的本地电脑上,点击绿色按钮 `Clone or download`,可以看到链接。链接有 `HTTPS``SSH` 两种,在这里,我选择 `HTTPS` 链接。
55+
56+
![clone-fork-doocs-leetcode](http://p9ucdlghd.bkt.clouddn.com/clone-fork-doocs-leetcode.png)
57+
58+
复制该链接,在命令行窗口中执行命令 “`git clone` + 刚才复制的 `HTTPS` 链接”,如:
59+
```
60+
git clone https://github.com/igayhub/leetcode.git
61+
```
62+
63+
注意啦,这里是 clone 自己帐户下(如: `igayhub`)的 leetcode 仓库,不是 doocs 下的噢。
64+
65+
命令执行的过程如下:
66+
```bash
67+
git clone https://github.com/igayhub/leetcode.git
68+
Cloning into 'leetcode'...
69+
remote: Enumerating objects: 77, done.
70+
remote: Counting objects: 100% (77/77), done.
71+
remote: Compressing objects: 100% (53/53), done.
72+
remote: Total 1177 (delta 32), reused 51 (delta 22), pack-reused 1100
73+
Receiving objects: 100% (1177/1177), 228.01 KiB | 11.00 KiB/s, done.
74+
Resolving deltas: 100% (495/495), done.
75+
Checking connectivity... done.
76+
77+
```
78+
79+
## 创建新分支
80+
克隆完成后,本地电脑就有一份代码了,`cd` 进入 `leetcode` 目录。
81+
```bash
82+
cd leetcode
83+
```
84+
85+
`git checkout` 命令创建新分支 `dev``dev` 为分支名,当然,你也可以命名为其它名字,这个看个人喜好~
86+
87+
```bash
88+
git checkout -b dev
89+
```
90+
91+
执行完上面的命令之后,可以看到,它创建并切换到新分支 `dev` 下了。
92+
```
93+
Switched to a new branch 'dev'
94+
```
95+
96+
## 做出更改并 commit
97+
之后你就在当前 `dev` 分支下对文件做出改动。你可以对仓库中的文件进行修改,或者创建新文件,添加 `Solution` 代码等。在这里我对 `Solution 020` 下的 `README.md` 文件做一下修改。
98+
```bash
99+
vim README.md
100+
```
101+
102+
修改后,执行 `add` 命令添加你的改动,然后执行 `commit` 命令提交你的改动到本地 Git。`-m` 之后是一些备注信息,备注信息要尽量体现你的改动,比如我是对 `Solution 020` 下的 `README.md` 做了修改,那么备注信息我就写 `Update solution 020 [README.md]`
103+
104+
```bash
105+
git add -A
106+
git commit -m "Update solution 020 [README.md]"
107+
108+
```
109+
110+
## 将改动发布到你的 GitHub 帐户
111+
执行命令:
112+
```bash
113+
git push origin dev
114+
```
115+
该命令会将代码 push 到你的 leetcode 仓库 dev 分支下,如果没有该分支,则会创建一个。此操作会弹出用户名密码输入框让你输入,输入完成之后,等待一会儿,在自己的 GitHub 上就能看到提交的结果啦~
116+
```bash
117+
Username for 'https://github.com': igayhub
118+
Password for 'https://igayhub@github.com':
119+
Counting objects: 5, done.
120+
Delta compression using up to 4 threads.
121+
Compressing objects: 100% (5/5), done.
122+
Writing objects: 100% (5/5), 510 bytes | 0 bytes/s, done.
123+
Total 5 (delta 4), reused 0 (delta 0)
124+
remote: Resolving deltas: 100% (4/4), completed with 4 local objects.
125+
remote:
126+
remote: Create a pull request for 'dev' on GitHub by visiting:
127+
remote: https://github.com/igayhub/leetcode/pull/new/dev
128+
remote:
129+
To https://github.com/igayhub/leetcode.git
130+
* [new branch] dev -> dev
131+
132+
```
133+
134+
## 提出 pull request
135+
push 之后,在你的 GitHub 项目上,可以看到 `Compare & pull request` 绿色按钮:
136+
137+
![dev-pull-request](http://p9ucdlghd.bkt.clouddn.com/dev-pull-request.png)
138+
139+
点击按钮,创建 pull request。
140+
141+
![create-pull-request](http://p9ucdlghd.bkt.clouddn.com/create-pull-request.png)
142+
143+
pull request 完成之后,我会收到一份邮件通知。
144+
145+
![email-of-pull-request](http://p9ucdlghd.bkt.clouddn.com/email-of-pull-request.jpg)
146+
147+
不久之后,如果 Review 完觉得没有问题的话,我会把你所有的 create/update 变化合并到这个项目的主分支。合并后,我想你应该也会收到电子邮件通知吧😁。这样也就完成了整个 contribute 过程啦~
148+
149+
## 与当前主分支保持同步
150+
如何将你的代码仓库与当前 `doocs/leetcode` 主分支保持同步呢?因为其它小伙伴也会把代码 merge 到主分支,而你的本地仓库没有这些代码,你需要同步一下~
151+
152+
首先,需要确保你在自己的 master 分支下,使用 `git status` 查看当前所在分支。
153+
154+
```bash
155+
git status
156+
On branch dev
157+
nothing to commit, working directory clean
158+
```
159+
160+
可以看到,当前是在 `dev` 分支下,所以应该使用 `git checkout` 切换到 `master`
161+
```bash
162+
git checkout master
163+
Switched to branch 'master'
164+
Your branch is up-to-date with 'origin/master'.
165+
```
166+
167+
然后,你需要添加远程主分支仓库 doocs/leetcode 到 git。执行命令:
168+
```bash
169+
git remote add upstream https://github.com/doocs/leetcode.git
170+
```
171+
172+
接着,利用 `git fetch` 命令获取远程仓库内容。
173+
```bash
174+
git fetch upstream
175+
```
176+
177+
该命令的执行过程如下:
178+
```bash
179+
remote: Enumerating objects: 35, done.
180+
remote: Counting objects: 100% (30/30), done.
181+
remote: Compressing objects: 100% (12/12), done.
182+
remote: Total 20 (delta 9), reused 16 (delta 7), pack-reused 0
183+
Unpacking objects: 100% (20/20), done.
184+
From https://github.com/doocs/leetcode
185+
* [new branch] master -> upstream/master
186+
```
187+
188+
最后,使用 `git rebase` 合并代码,并 push 到你的 GitHub 仓库。
189+
```bash
190+
git rebase upstream/master
191+
First, rewinding head to replay your work on top of it...
192+
Fast-forwarded master to upstream/master.
193+
```
194+
195+
push 的时候,一样需要输入你的 GitHub 用户名和密码噢~
196+
```bash
197+
git push origin master
198+
Username for 'https://github.com': igayhub
199+
Password for 'https://igayhub@github.com':
200+
Counting objects: 20, done.
201+
Delta compression using up to 4 threads.
202+
Compressing objects: 100% (19/19), done.
203+
Writing objects: 100% (20/20), 5.62 KiB | 0 bytes/s, done.
204+
Total 20 (delta 9), reused 0 (delta 0)
205+
remote: Resolving deltas: 100% (9/9), completed with 6 local objects.
206+
To https://github.com/igayhub/leetcode.git
207+
d8fdeb6..5a088d3 master -> master
208+
```
209+
210+
😊现在,所有仓库就都同步啦~
211+
212+
## 资料相关
213+
214+
- [😲了解更多 Git 相关,点这里噢。](https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000)
215+
- [🤭如何在 GitHub 上用 Markdown 写作,看这儿。](https://github.com/guodongxiaren/README)
216+
- [😄如何写出赏心悦目的中文技术文档,这儿有推荐。](https://github.com/ruanyf/document-style-guide)

.gitignore

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/gradle/wrapper/gradle-wrapper.properties
2+
##----------Android----------
3+
# build
4+
*.apk
5+
*.ap_
6+
*.dex
7+
*.class
8+
bin/
9+
gen/
10+
build/
11+
12+
# gradle
13+
.gradle/
14+
gradle-app.setting
15+
!gradle-wrapper.jar
16+
build/
17+
18+
local.properties
19+
20+
##----------idea----------
21+
*.iml
22+
.idea/
23+
*.ipr
24+
*.iws
25+
26+
# Android Studio Navigation editor temp files
27+
.navigation/
28+
29+
##----------Other----------
30+
# osx
31+
*~
32+
.DS_Store
33+
gradle.properties
34+
35+
.vscode

0 commit comments

Comments
 (0)