如何仅在git中复制和替换分支中的一些项目文件(how to copy and replace some project files in a branch only in git)
我在bitBucket中创建了一个新的项目存储库,我也有本地副本。 现在,我已经从master创建了一个名为“xyz”的分支。
在我创建另一个项目存储库之前,我和我的团队成员在这个存储库上工作。 我正在使用主存储库,我的一个团队成员在本地检查了它(我作为管理员已将他添加到bitBucket中)并继续在本地工作。 之后他给我发了完整的项目文件夹。
没有如上所述由于许多冲突问题,我在bitBucket中创建了另一个新的存储库,并将来自我旧存储库中的主服务器的文件和文件夹放入其中。 现在我已经在新的存储库中创建了一个分支,我想放置文件和文件夹(许多文件和文件夹将是多余的,我想将所有这些冗余文件和文件夹替换为此分支“xyz”),我的团队成员只被送到这个分支(“xyz”)。
任何人都可以帮我解决这个问题。 我不知道如何在git中本地执行它然后将其推送到远程的特定分支。
I have created a new project repository in bitBucket and I have the local copy also. Now, I have created a branch from master called "xyz".
Before I had created another project repository and me and my team member worked on this repository. I was working on master repository and one of my team member has checkout it (I as admin has added him in bitBucket) locally and continued working locally. After that he sent me the complete project folder.
No as mentioned above due to many conflict problems, I created another new repository in bitBucket and put the files and folders from the master in my old repository into it. Now I have created a branch in the new repository and I would like to put the files and folders (many files and folder will be redundant and I would like to replace all of these redundant files and folders into this branch "xyz"), my team member sent into this branch only ("xyz").
Could anyone please help me with this problem. I don't know how to do it locally in git and then to push it into the specific branch at remote.
原文:https://stackoverflow.com/questions/40869834
最满意答案
假设您的第一个回购名称是
repo-1
,新回购名称是repo-2
。 现在转到repo-1和repo-2然后结帐master
分支。$ git checkout master # checkout master(repo-1) $ git checkout master # checkout master(repo-2)
现在复制所有repo-1文件夹/文件
(except .git folder)
并粘贴到repo-2中。
然后在将repo的分支更改为
xyz
之后重复该过程。$ git checkout xyz # checkout xyz(repo-1) $ git checkout xyz # checkout xyz(repo-2)
现在复制所有repo-1文件夹/文件
(except .git folder)
并粘贴到repo-2中。
Say your first repo name is
repo-1
and new repo name isrepo-2
. Now go to both repo-1 and repo-2 then checkoutmaster
branch.$ git checkout master # checkout master(repo-1) $ git checkout master # checkout master(repo-2)
Now copy all of your repo-1 folders/files
(except .git folder)
and paste inside repo-2.
Then repeat the procedure after changing both of repo's branch to
xyz
.$ git checkout xyz # checkout xyz(repo-1) $ git checkout xyz # checkout xyz(repo-2)
Now copy all of your repo-1 folders/files
(except .git folder)
and paste inside repo-2.
相关问答
更多-
因为你不想在树中移动文件,所以你应该可以只需要检出目录: git checkout master -- dirname As you are not trying to move the files around in the tree, you should be able to just checkout the directory: git checkout master -- dirname
-
此解决方案似乎只适用于git的某些修补版本。 看到一个新的答案指向解决方法和另一个答案和后续的意见提示哪些版本可能工作。 我写了一篇关于如何有效地使用不同分支的excludesfile的博客文章,比如一个用于public github,一个用于heroku部署。 这里是快速和肮脏的: $ git branch public_viewing $ cd .git/ $ touch info/exclude_from_public_viewing $ echo "path/to/secret/file" > in ...
-
git最重要的特性之一是git是一个分布式版本控制系统。 这意味着您的本地分支不需要与远程分支同步。 在您的特定情况下,您的计算机上有一个master 。 当您执行git checkout -b newbranch ,您创建了一个新分支,它与您机器上的master分支相同。 但是,远程计算机上还有一个名为origin的master服务器(如果使用它,可能是GitHub)。 因此,当您执行git pull origin master ,您正在将本地newbranch与远程origin/master合并而不是本 ...
-
GIT替换分支的内容(GIT replace branch's contents)[2020-11-10]
听起来像--s ours的merge选项正是您所需要的。 http://book.git-scm.com/5_advanced_branching_and_merging.html Decided the simplest way to fix it was to do this: clone the repo twice, once into a dev folder once into a stage folder then cd dev git rm -rf * git commit -a -m "t ... -
已删除分支中的Git文件仍存在于我的项目目录中(Git files in removed branch still exists in my project directory)[2022-05-26]
如果你在Git存储库中创建新文件但是没有git commit它们,Git就不管理它们。 这意味着更改分支,更改提交或还原更改不会影响这些新文件 。 您可以手动删除这些新文件,也可以运行git clean ,删除未版本控制的文件。 要删除您添加的文件,请运行 git clean -n 这将让你看到Git将删除它们之前删除的文件,这样你就可以确定它不会影响你想保留的任何文件。 一旦你确定它只会影响你想要摆脱的文件,就运行吧 git clean -f -d 有关更多信息,请参阅此问题 。 If you cre ... -
你只能分支整个项目。 但是,没有人阻止您更改分支中的这两个文件。 然后,您可以简单地合并这些分支以传播更改。 you can only branch the full project. however, nobody prevents you from changing just those two files in the branch. you can then simply merge those branches to propagate the changes.
-
git branch branch_name创建一个新分支但不切换到它。 git checkout -b branch_name创建一个新分支并切换到它。 如果您在git branch branch_name之后进行了更改然后提交,则它们将被提交到您已检出的最后一个分支。 There have been a .gitignore file checked in both localconf and feature-a-b preventing any changes while switching bran ...
-
使用这些命令: git checkout B git pull origin B 您: 切换到分支B 将分支B的本地状态与其远程状态同步 当您运行git checkout A您更改了工作副本 - A和B具有不同的历史记录 - 因此不同的文件。 你需要的是将分支B 合并到A或者将其重新绑定 。 如果你是一个git初学者更好的选择是合并: git checkout A git merge --no-ff B --no-ff将添加合并提交,即使合并是快进 。 With these to commands: g ...
-
Git - 如何自动将目录中的更改推送到另一个分支(Git - How to auto push changes in a directory to another branch)[2021-08-25]
你真的不需要这种复杂的方法。 只需添加您自己的repo作为子模块(本身!), gh-pages分支后面的子模块(因为子模块可以跟随最新的分支提交 )! git checkout master git rm -r gh-pages # save your data first git submodule add -b gh-pages -- /remote/url/of/your/own/repo git commit -m "ADd gh-pages branch as submodule" git pus ... -
如何仅在git中复制和替换分支中的一些项目文件(how to copy and replace some project files in a branch only in git)[2022-05-16]
假设您的第一个回购名称是repo-1 ,新回购名称是repo-2 。 现在转到repo-1和repo-2然后结帐master分支。 $ git checkout master # checkout master(repo-1) $ git checkout master # checkout master(repo-2) 现在复制所有repo-1文件夹/文件(except .git folder)并粘贴到repo-2中。 然后在将repo的分支更改为xyz之后重复该过程。 $ gi ...