copy maven dependencies to a folder

background

一个简单的需求,当你的同事需要调试代码的时候,他并不想建立maven环境,这时候依赖的jar包 该如何导出呢?

no code say nothing

这时候你需要的是maven-dependency-plugin

添加依赖配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<!-- copy-dependency plugin -->
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>

此处的<outputDirectory> 指定了你导出jar包的路径.

执行命令 mvn dependency:copy-dependencies

查看项目多了一个/alternateLocation目录,并且依赖的jar包都下载到这个目录下了。

how to use nginx on windows

1. Download nginx lastest release from here.

2. unzip to your local driver. eg: c:/apps/nginx

3. start nginx

1
2
cd c:/apps/nginx
start nginx

4. monitoring nginx process

1
2
3
4
5
tasklist /fi "imagename eq nginx.exe"
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
nginx.exe 11700 Console 1 10,696 K
nginx.exe 1160 Console 1 11,180 K

notice
一个是主进程(main process),另一个是工作进程(work process).如果启动失败,请查看错误日志logs\error.log

5. visit http://localhost:8080

6. configuration file nginx.conf

reference config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
error_log logs/error.log;
http {
include mime.types;
default_type application/octet-stream;
server {
listen 8080;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
...
}

7. the command list of nginx:

1
2
3
4
nginx -s stop 快速退出
nginx -s quit 优雅退出
nginx -s reload 更换配置,启动新的工作进程,优雅的关闭以往的工作进程
nginx -s reopen 重新打开日志文件

how git changing author info

背景

  1. gitlab中的统计视图是根据用户的信息统计工作量
  2. 迁移git repo中经常会遇到用户和邮箱不一致的情况

解决思路

那么如何修改已经推送到远程的author信息呢?

github 官方提供的建议如何变更用户信息

同时也有类似的项托管在github上,git-tips-blame-someone-else

思路基本一致,就是替换提交记录、分支、标签里的author信息。

方案

1.打开终端或命令行(git bash)

2.创建一个你项目的全新裸库

1
2
git clone --bare https://github.com/user/repo.git
cd repo.git

3.复制粘贴脚本,并根据你的信息修改下面的变量:

1
2
3
OLD_EMAIL
CORRECT_NAME
CORRECT_EMAIL

脚本replace.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-email@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags

4.执行这个脚本

sh replace.sh

5.察看Git历史有没有错误

git log

6.强制推送到远程

git push --force --tags origin 'refs/heads/*'

7.清除repo.git仓库

1
2
cd ..
rm -rf repo.git

场景

远程有一个develop分支,我想获取到本地,但是clone该项目的时候这个远程分支还没有创建,于是执行 git checkout commit_id(develop) 提示如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ git checkout f7c774b
Checking out files: 100% (357/357), done.
Note: checking out 'f7c774b'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at f7c774b... update jeffsui.github.io

出现 detached from ...

此时用git branch -av察看分支

1
2
3
4
5
6
7
$ git branch -av
* (detached from f7c774b) f7c774b update jeffsui.github.io
master 6ce1857 Site updated: 2016-08-07 22:09:10
remotes/origin/HEAD -> origin/master
remotes/origin/develop f7c774b update jeffsui.github.io
remotes/origin/gh-pages 1eee93f Site updated: 2016-02-13 21:03:46
remotes/origin/master 6ce1857 Site updated: 2016-08-07 22:09:10

所谓的 detached HEAD 其实就是HEAD指向的是一个commit而不指向任何一个branch的临时分支,翻译过来就是游离.

众所周知,每一个分支都对应了一个commit,git checkout其实就是修改HEAD文件内容,让它指向不同的分支.

如何让detached HEAD所处分支指向远程分支

此时的分支你可以执行commit操作,但是无法push到远程分支。
那么我们如何把游离状态的分支指向我们指定的远程分支呢。

1
2
3
$ git fetch origin develop:develop
From https://github.com/jeffsui/jeffsui.github.io
* [new branch] develop -> develop

继续执行git branch -av 命令查看分支

1
2
3
4
5
6
7
8
$ git branch -av
* (detached from f7c774b) f7c774b update jeffsui.github.io
develop f7c774b update jeffsui.github.io
master 6ce1857 Site updated: 2016-08-07 22:09:10
remotes/origin/HEAD -> origin/master
remotes/origin/develop f7c774b update jeffsui.github.io
remotes/origin/gh-pages 1eee93f Site updated: 2016-02-13 21:03:46
remotes/origin/master 6ce1857 Site updated: 2016-08-07 22:09:10

此时我们发现多了一个develop分支指向了远程develop 分支,这样我们就可以通过命令git push origin develop:develop到远程分支了。

更简洁的方法

git fetch origin develop:develop

or

git checkount -b origin develop:develop 这样可以直接获取远程分支并创建一个本地分支。