简体   繁体   English

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

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

We have a website at work which we keep two copies of - one is the live site, or master copy and the other is a test / staging site where big changes are made and tested before copying them over - manually at the moment - to the live site and published. 我们有一个工作中的网站,我们保留两个副本-一个是实时站点,或者是主副本,另一个是测试/暂存站点,在进行较大更改并进行测试之前,此刻将它们手动复制到现场发布。

We've just finished a checkout overhaul on the site which has led to the creation or modification of about 40 files. 我们刚刚在该网站上完成了一次检修工作,导致创建或修改了大约40个文件。

My question is this: 我的问题是这样的:

can we create two git branches, one for each site, and then use git to generate a list of differences and merge the test changes into the live site, even though the site isn't CURRENTLY under version control? 我们可以创建两个git分支,每个站点一个,然后使用git生成差异列表并将测试更改合并到实时站点中,即使该站点当前不受版本控制吗?

You can easily do it by initializing a git repo for your website. 您可以通过为您的网站初始化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"

Now that your prod site is under version control, create a branch then copy your staging website on it. 现在您的产品站点已受版本控制,创建一个分支,然后在其上复制您的暂存网站。

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

Now you have two branches: 现在您有两个分支:

  • master with your prod website master您的产品网站
  • staging with your staging website staging与暂存网站

Now you can list differences between your two branches with a git diff 现在您可以使用git diff列出两个分支之间的git diff

git diff master..staging

Yes you can do it. 是的,你可以做到。

You have several options: But why not using beyond compare for example? 您有几种选择:但是为什么不使用超越比较呢?


Using branches 使用分支

# 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 

Viewing view the diff 查看差异

The simple way is to use git status before you are adding the content of the second branch to git 简单的方法是在将第二个分支的内容添加到git之前使用git status

Before you do this form the previous step: 在执行此操作之前,请完成上一步:

git status git状态

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

# display the differences between the branches
git status

or # show the differences between the current HEAD and the content waiting # to be committed git add . 或#显示当前HEAD与等待提交的内容git add之间的差异。 git diff git diff

在此处输入图片说明

View changes 查看变更

You can view the differences between the branch sin many ways 您可以通过多种方式查看分支罪之间的区别

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

and more... 和更多...

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

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