Git 常用操作

修改 D:/Program Files/Git/etc/bash.bashrc
增加:
export GIT_SSH=D:/Program\ Files/TortoiseGit/bin/TortoiseGitPlink.exe
pageant.exe D:/Program\ Files/TortoiseGit/XXXX.ppk &
alias mysql=”winpty mysql”

修改 C:/Users/Administrator/.gitconfig
增加
[alias]
lg = log –color –graph –pretty=format:’%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset’ –abbrev-commit
[ssh]
variant = ssh

二、熟悉Git 相关命令
git-cheatsheet.pdf

三、git 操作流程:

命令行模式:
->右键 Git Bash Here

拉取项目到本地
git clone ssh://git@gitlab.xxx.com:port/repos.git XXX
查看已有的分支
git branch -av
查看当前仓库的地址
git remote -v
创建自己的分支
git checkout -b xxx_develop origin/develop
删除指定分支
git branch -d

1、准备工作的时候,切换到自己的分支
git checkout xxx_develop

2、把开发服的文件同步到自己的分支
git merge origin develop

3、修改代码…

4、代码处理完后,把自己改的东西提交到自己的分支

查看改变的文件
git status  

不确定的文件可以对比查看
git diff 路径/文件名

增加所有文件到缓存仓库
git add . 

提交缓存仓库内容到本地分支
git commit -m"这里写本次提交的修改描述"

把本地分支推送到远端分支 
git push origin/xxx_develop

5、把本次修改内容合并到开发服分支上
切换到开发服分支
git checkout develop

拉取远端最新的代码
git pull

合并自己的分支到开发服分支
git  merge  origin xxx_develop

成功合并的话把合并后的代码推送到开发服
git push

合并冲突:先解决冲突再提交,解决冲突最好用 TortoiseGit 

redmine 安装

官方安装文档:http://www.redmine.org/projects/redmine/wiki/RedmineInstall

创建数据库
CREATE DATABASE redmine CHARACTER SET utf8;
CREATE USER 'redmine'@'localhost' IDENTIFIED BY 'my_password';
GRANT ALL PRIVILEGES ON redmine.* TO 'redmine'@'localhost';

安装redmine主体

https://www.redmine.org/releases/redmine-4.2.6.tar.gz

tar -xzvf redmine-4.2.6.tar.gz
cd redmine-4.2.6
cp config/database.yml.example config/database.yml
vim config/database.yml
production:
  adapter: mysql2
  database: redmine
  host: localhost
  username: redmine
  password: "password"
  encoding: utf8

 show global variables like ‘port’; 非3306 需

production:
  adapter: mysql2
  database: redmine
  host: localhost
  port: 3307
  username: redmine
  password: "password"
  encoding: utf8

编译安装ruby

https://www.ruby-lang.org/en/news/

tar -xzvf ruby-2.5.5.tar.gz
cd ruby-2.5.5
mkdir -p /usr/local/ruby
./configure --prefix=/usr/local/ruby
make && make install
ruby --version  #检测ruby是否安装正常
ln -s /usr/local/ruby/bin/ruby /usr/local/bin/ruby
export PATH=$PATH:/usr/local/ruby/bin

安装rubygem

https://rubygems.org/pages/download

tar -xzvf rubygems-3.3.14.tar.gz
cd rubygems-3.3.14
ruby setup.rb
gem -v

安装bundler

gem install bundler
gem install rubyzip

cd /usr/local/redmine-4.0.2

方案1:

安装ImageMagick-6.9.8-3.tar.gz
./configure --prefix=/usr/local/ImageMagic
make && make install
echo '/usr/local/ImageMagic/lib/' >> /etc/ld.so.conf.d/server.conf
ldconfig
strings /etc/ld.so.cache |grep ImageMagic
vim /etc/profile
echo $PKG_CONFIG_PATH
export PKG_CONFIG_PATH=/usr/local/ImageMagic/lib/pkgconfig/:$PKG_CONFIG_PATH
bundle install --without development test

方案2:

RMagick (allows the use of ImageMagick to manipulate images for PDF and PNG export)
bundle install --without development test rmagick
创建会话密钥
bundle exec rake generate_secret_token
创建数据库结构
RAILS_ENV=production bundle exec rake db:migrate
插入默认配置数据库中的数据
RAILS_ENV=production bundle exec rake redmine:load_default_data
选择系统语言
Select language: ar, bg, bs, ca, cs, da, de, el, en, en-GB, es, et, eu, fa, fi, fr, gl, he, hr, hu, id, it, ja, ko, lt, lv, mk, mn, nl, no, pl, pt, pt-BR, ro, ru, sk, sl, sq, sr, sr-YU, sv, th, tr, uk, vi, zh, zh-TW [en] zh
权限管理
mkdir -p tmp tmp/pdf public/plugin_assets
chmod -R 755 files log tmp public/plugin_assets
sudo find files log tmp public/plugin_assets -type f -exec chmod -x {} +

启动:
nohup bundle exec rails server webrick -e production -b 0.0.0.0 &

浏览器访问:192.168.110.110:3000

login: admin
password: admin

无法登录时,需要开放3000端口

vim /etc/sysconfig/iptables

/etc/init.d/iptables restart

firewall-cmd –zone=public –add-port=3000/tcp –permanent

firewall-cmd –reload

启动: 

ps -ef |grep ruby

kill Port

nohup bundle exec rails server webrick -e production -b 0.0.0.0 &

vim  nohup.txt  检查是否报错

以下是init 脚本代码:

#!/bin/sh
#
# redmine       Redmine Daemon
#
# chkconfig: - 99 36
# description: Remine Daemon
. /etc/rc.d/init.d/functions

HOMEPATH=/usr/local/redmine-4.2.6
PIDFILE=$HOMEPATH/tmp/pids/server.pid
PARAMS="-e production -b 0.0.0.0 -d"
SERVER=webrick

cd $HOMEPATH

start(){
        echo 'Starting redmine...'
        /usr/local/ruby/bin/bundle exec /usr/local/ruby/bin/rails server $SERVER $PARAMS
        RETVAL=$?
        return $RETVAL
}

stop(){
        echo -n 'Stopping redmine...'
        killproc -p $PIDFILE -INT
        RETVAL=$?
        return $RETVAL
}

status(){
        echo -n 'Redmine is '
        if [ -f $PIDFILE ]
        then
                PID=`/bin/cat $PIDFILE`
                STATUS=`/bin/ps -p $PID`
                RETVAL=$?
                if [ $RETVAL -eq 0 ]
                then
                        echo 'running.'
                        return $RETVAL
                fi
        fi
        echo 'not running.'
}

case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                stop
                start
                echo
                ;;
        status)
                status
                ;;
        *)
                echo "Usage $0 {start|stop|status|restart}"
                exit 1
esac

将以上脚本保存为 /etc/init.d/redmine 后,就可以使用 chkconfig 来配置随系统启动了:

chmod +x  /etc/init.d/redmine

chkconfig –add redmine

chkconfig redmine on

重启脚本:

cat > redmine.sh <<EOF

#/bin/bash

# redmine 启动

#——————

kill $(cat /usr/local/redmine-3.3.0/tmp/pids/server.pid)

nohup /usr/local/bin/bundle exec /usr/local/bin/rails server webrick -e production -b 0.0.0.0 &

EOF

备份和恢复

备份和恢复 是企业应用中永远存在的话题.

Redmine的用户和问题等信息存储于Mysql数据库,表名为redmine而附件等资源存储于Redmine安装目录的files目录下.

因此需要迁移的话只需要备份Mysql数据库的对应的表和files目录即可。

1.备份mysql数据库。

查看redmine/mysql/config/database.yml

记住production字段的username和password。

然后控制台root权限执行:mysqldump -u username -p passwd redmine > /path/redmine_bak.sql

然后是备份附件。

$ cd redmine

$ tar cvzf /var/files_bak.tar.gz ./files/

2、Redmine恢复

附件库恢复

直接将备份的/var/files_bak.tar.gz解压缩到/redmine/files目录下即可

Mysql恢复

在root用户下运行:

$ mysql -u root -p redmine < /var/redmine_bak.sql

3、恢复完毕后启动Redmine,

$ cd redmine

$ ruby script/server -e production

如果页面有乱码,可编辑redmine/mysql/config/database.yml,将production字段的encoding注释掉即可。