繁体   English   中英

使用git合并尚未受版本控制的网站

[英]Use git to merge sites that aren't already under version control

我们有一个工作中的网站,我们保留两个副本-一个是实时站点,或者是主副本,另一个是测试/暂存站点,在进行较大更改并进行测试之前,此刻将它们手动复制到现场发布。

我们刚刚在该网站上完成了一次检修工作,导致创建或修改了大约40个文件。

我的问题是这样的:

我们可以创建两个git分支,每个站点一个,然后使用git生成差异列表并将测试更改合并到实时站点中,即使该站点当前不受版本控制吗?

您可以通过为您的网站初始化git repo轻松地做到这一点。

cd prod_site
git init
git add -A #You may want to ignore some files like libraries for example, use a .gitignore
git commit -m "Initial prod commit"

现在您的产品站点已受版本控制,创建一个分支,然后在其上复制您的暂存网站。

git checkout -b staging
cp -r /path/to/staging/website .
git commit -am "Staging website"

现在您有两个分支:

  • master您的产品网站
  • staging与暂存网站

现在您可以使用git diff列出两个分支之间的git diff

git diff master..staging

是的,你可以做到。

您有几种选择:但是为什么不使用超越比较呢?


使用分支

# cd to the desired folder
# place the content of the first branch in the folder

# init the folder as git repository
git init

# add all the files in the directory and commit them to stash
git add . -A
git commit 

# create a new branch for the second content
git checkout -b <b2>

# now copy the second content to this folder

# add the content of the second branch to git
git add . -A

# commit the changes
git commit 

查看差异

简单的方法是在将第二个分支的内容添加到git之前使用git status

在执行此操作之前,请完成上一步:

git状态

# now copy the second content to this folder
git add . -A
git commit 

# display the differences between the branches
git status

或#显示当前HEAD与等待提交的内容git add之间的差异。 git diff

在此处输入图片说明

查看变更

您可以通过多种方式查看分支罪之间的区别

git log --cc
git log master ^b1
git log ^master b1     
gir format-patch HEAD~1

和更多...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM