VMWare ESXi创建虚拟机并在虚拟机上搭建私有git

创建虚拟机的流程主要是参考https://blog.csdn.net/weixin_41877978/article/details/99625811 ,这里不做过多的阐述。

一、在创建的过程中需要注意以下三点:

1、在手动分区的时候,可以点击“点这里自动创建他们(C)”,快速创建,也可以手动自己创建。

2、测试自己网络的时候要确保自己的ip是没有被占用的。

3、如果需要连接xshell类似的远程连接软件,要确保自己的ssh配置是打开的。

二、排查自己的ssh是否开启的方法:

1.利用 rmp -qa | grep ssh 命令 查看ssh是否安装;

VMWare ESXi创建虚拟机并在虚拟机上搭建私有git_第1张图片

 2.如果没有安装可以利用命令 yum install ssh  安装ssh;

VMWare ESXi创建虚拟机并在虚拟机上搭建私有git_第2张图片

 3.安装成功后用命令 ps -ef | grep ssh  启动ssh,出现以下情况说明已经启动;

 4.还可以用命令   service sshd start  重启;

 5.查看ssh配置文件

  6.查看配置是否正确

VMWare ESXi创建虚拟机并在虚拟机上搭建私有git_第3张图片

VMWare ESXi创建虚拟机并在虚拟机上搭建私有git_第4张图片

三、搭建虚拟机中的git。

1、安装 git 和 git-daemon(命令:yum install -y git   和   yum install -y git-daemon)

VMWare ESXi创建虚拟机并在虚拟机上搭建私有git_第5张图片

VMWare ESXi创建虚拟机并在虚拟机上搭建私有git_第6张图片

 2、 创建git目录,可以选择自己系统文件夹相对存储剩余较大的文件夹创建。

3、创建git仓库,自己命名(进入到刚才创建的目录里创建仓库)。

 4、进入刚才创建的仓库文件中,初始化仓库,使用命令:git --bare init。

初始化命令还有 git init ,但是如果我们是团队协作,多人共同开发的时候,要使用上面的命令初始化,两个命令的具体区别可以自行查阅,这里不做详细解释。

5、修改仓库的mod权限,并设置默认新建的文件和文件夹同属于父目录的用户组。

修改mod权限命令: 

chmod 775 test/ -R

设置默认用户组命令:

chmod g+s test -R

set -m g:root:rwx test

 6、启动Git deamon服务

 到这里,虚拟机中的仓库就已经创建好了,下面介绍怎么使用sourcetree连接仓库并进行操作。

四、使用sourcetree连接虚拟机中创建的仓库。

1、安装sourcetree可视化软件,安装过程不再说明。

2、安装好后,克隆刚才已经创建好的仓库到本地。

VMWare ESXi创建虚拟机并在虚拟机上搭建私有git_第7张图片

3、填写好地址后,软件会自动检查是否是一个仓库,然后会出现一个登陆框,输入自己虚拟机的账户名密码后点击确定(勾选记住密码)。 

 4、可以设置ssh免密登陆,需要先在自己的本地(命令: ssh-keygen -t rsa )生成秘钥。

VMWare ESXi创建虚拟机并在虚拟机上搭建私有git_第8张图片

 5、把把 id_rsa.pub 上传到虚拟机,并将 id_rsa.pub 内容追加(这儿的 >> 表示追加的意思,不然很可能就把文件里边原有的东西给覆盖掉了)到 authorized_keys 里边去:

 6、将秘钥id_rsa导入到sourcetree中,并启动ssh助手。(具体过程可参考:https://jingyan.baidu.com/article/9faa7231cdec65473d28cb11.html)或自行查询。

四、客户端使用sourcetree进行word文档协同

当安装好git后,同步word文档,看不到对比,解决方法如下:

(因为word不是纯粹的二进制文件,所以需要先将其转换成二进制文件)

1、下载pandoc软件(去http://pandoc.org/installing.html 找到合适的pandoc下载文件,或者网上自行下载,网盘下载:链接:https://pan.baidu.com/s/1u8aCPTJVbxyO5AFt1hhIqQ 提取码:zk6b) ,然后安装。

2、 如果是在 unix(linux/macosx)系统下,编辑 ~/.gitconfig 文件,如果是在windows系统下,编辑 git 安装目录下的 /mingw64/etc/gitconfig 文件,加上这么一段话:

[diff "pandoc"]
  textconv=pandoc --to=markdown
  prompt = false
[alias]
  wdiff = diff --word-diff=color --unified=1

3、然后在你的工程目录下新建一个 .gitattributes(linux/mac)文件(windows是gitattributes 文件),然后写入:
*.docx diff=pandoc
*.doc	diff=pandoc
*.DOC	diff=pandoc
*.docx	diff=pandoc
*.DOCX	diff=pandoc

4、但是这个时候你提交的时候可以看到差别,但是历史记录中看不到差别,需要手动把文件转换为md文件,然后提交,也可以设置 git hooks 以启用自动生成和跟踪 .docx 文件的 Markdown 副本。在自己的仓库的文件路径中\.git\hooks中添加文件post-commit和pre-commit。

post-commit内容为:

#!/bin/bash

# ========================================================================
# SUMMARY
# ========================================================================
#
# "pre-commit-git-diff-docx.sh": Small git (https://git-scm.com/)
# hook. It works in combination with another hook,
# "pre-commit-git-diff-docx.sh".
#
# Together, they keep a Markdown (.md) copy of .docx files so that git
# diffs of the .md files show the changes in the document (as .docx
# files are binaries, they produce no diffs that can be checked in
# emails or in the repository's commit page).
#
# ========================================================================
# DEPENDENCIES
# ========================================================================
#
# pre-commit-git-diff-docx.sh
# pandoc (http://pandoc.org/)
#
# ========================================================================
# INSTALLATION
# ========================================================================
#
# See pre-commit-git-diff-docx.sh
#
# ========================================================================
# DETAILS:
# ========================================================================
#
# This script checks whether file .commit-amend-markdown exists. If it
# exists, it amends the previous commit adding the names of .md files
# inside it.

# Author: Ramon Casero 
# Version: 0.1.0
# Copyright © 2016 University of Oxford
# 
# University of Oxford means the Chancellor, Masters and Scholars of
# the University of Oxford, having an administrative office at
# Wellington Square, Oxford OX1 2JD, UK. 
#
# This file is part of Gerardus.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details. The offer of this
# program under the terms of the License is subject to the License
# being interpreted in accordance with English Law and subject to any
# action against the University of Oxford being under the jurisdiction
# of the English Courts.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .

# go to the top directory of this project, because filenames are
# referred to that location
cd `git rev-parse --show-toplevel`

# check whether the commit included .docx files that were converted to
# markdown (.md) format
if [ -a .commit-amend-markdown ]
then

    # add Mardown versions (.md) of the .docx files to amend the
    # commit
    cat .commit-amend-markdown | xargs git add || {
    	echo "Git cannot add Markdown files to amend the commit";
    	exit 1;
    }

    # delete the file with the list of Markdown files to avoid an
    # infinite loop
    rm .commit-amend-markdown

    # add the .md file by amending the last commit
    ## --no-verify: prevent infinite loop, don't go into the pre-commit
    ##              hook again
    echo Amend last commit adding .md files
    git commit --amend -C HEAD --no-verify || {
    	echo "Git cannot amend the commit";
    	exit 1;
    }

fi
exit

pre-commit内容为:

#!/bin/bash

# ========================================================================
# SUMMARY
# ========================================================================
#
# "pre-commit-git-diff-docx.sh:" Small git (https://git-scm.com/)
# hook. It works in combination with another hook,
# "post-commit-git-diff-docx.sh".
#
# Together, they keep a Markdown (.md) copy of .docx files so that git
# diffs of the .md files show the changes in the document (as .docx
# files are binaries, they produce no diffs that can be checked in
# emails or in the repository's commit page).
#
# ========================================================================
# DEPENDENCIES
# ========================================================================
#
# post-commit-git-diff-docx.sh
# pandoc (http://pandoc.org/)
#
# ========================================================================
# INSTALLATION
# ========================================================================
#
#   1) put both scripts in the hooks directory of each of your git
#      projects that use .docx files. There are several options,
#      e.g. you can put them in ~/Software and soft link to them from
#      the hooks directory, e.g.
#
#      cd $PROJECTPATH/.git/hooks
#      ln -s ~/Software/pre-commit-git-diff-docx.sh pre-commit
#      ln -s ~/Software/post-commit-git-diff-docx.sh post-commit
#
#      or you can make a copy in the hooks directory
#
#      cd $PROJECTPATH/.git/hooks
#      cp ~/Software/pre-commit-git-diff-docx.sh pre-commit
#      cp ~/Software/post-commit-git-diff-docx.sh post-commit
#
#   2) make sure that the scripts are executable
#
#      cd ~/Software
#      chmod u+x pre-commit-git-diff-docx.sh post-commit-git-diff-docx.sh
#
#
# ========================================================================
# DETAILS:
# ========================================================================
#
# This script makes a Markdown format copy (.md) of any .docx files in
# the commit. It then lists the .md file names in a temp file called
# .commit-amend-markdown.
#
# After the commit, the post-commit hook
# "post-commit-git-diff-docx.sh" will check for this file. If it
# exists, it will amend the commit adding the names of the .md files.
#
# The reason why we cannot simply add the .md files here is because
# `git add` adds files to the next commit, not the current one.
#
# This script requires pandoc (http://pandoc.org/) to have been
# installed in the system.

# Author: Ramon Casero 
# Version: 0.3.0
# Copyright © 2016-2017 University of Oxford
# 
# University of Oxford means the Chancellor, Masters and Scholars of
# the University of Oxford, having an administrative office at
# Wellington Square, Oxford OX1 2JD, UK. 
#
# This file is part of Gerardus.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details. The offer of this
# program under the terms of the License is subject to the License
# being interpreted in accordance with English Law and subject to any
# action against the University of Oxford being under the jurisdiction
# of the English Courts.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .

# abort commit if pandoc is not installed
pandoc -v >/dev/null 2>&1 || { 
    echo >&2 "I require pandoc to keep track of changes in .docx files but it's not installed. Aborting."; 
    exit 1; 
}

# go to the top directory of this project, because filenames will be
# referred to that location
cd `git rev-parse --show-toplevel`

# delete temp file with list of Mardown files to amend commit
rm -f .commit-amend-markdown

# create a Markdown copy of every .docx file that is committed, excluding deleted files
for file in `git diff --cached --name-only --diff-filter=d | grep "\.docx$"`
do
    # name of Markdown file
    mdfile="${file%.docx}.md"
    echo Creating Markdown copy of "$file"
    #echo "$mdfile"

    # convert .docx file to Markdown
    pandoc "$file" -o "$mdfile" || {
    	echo "Conversion to Markdown failed";
    	exit 1;
    }

    # list the Markdown files that need to be added to the amended
    # commit in the post-commit hook. Note that we cannot `git add`
    # here, because that adds the files to the next commit, not to
    # this one
    echo "$mdfile" >> .commit-amend-markdown

done

# remove the Markdown copy of any file that is to be deleted from the repo
for file in `git diff --cached --name-only --diff-filter=D | grep "\.docx$"`
do
    # name of Markdown file
    mdfile="${file%.docx}.md"
    echo Removing Markdown copy of "$file"

    if [ -e "$mdfile" ]
       then
	   # delete the Markdown file
	   git rm "$mdfile"
	   
	   # list the Markdown files that need to be added to the
	   # amended commit in the post-commit hook. Note that we
	   # cannot `git add` here, because that adds the files to the
	   # next commit, not to this one
	   echo "$mdfile" >> .commit-amend-markdown
    fi

done

手动设置如下:

  1. 从 linux 或 Windows 命令行运行 pandoc。这将创建您的文件的 Markdown 版本(没有数字,但有乳胶格式的方程)

     pandoc -s file.docx -t markdown -o file.md
    
  2. 更新变更日志

  3. 使用 git 提交两个文件

     git add file.docx file.md
     git commit

你可能感兴趣的:(问题解决,虚拟机,vmware,git,私有仓库,word协同)