首页 \ 问答 \ 如何仅在git中复制和替换分支中的一些项目文件(how to copy and replace some project files in a branch only in git)

如何仅在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
更新时间:2022-05-16 20:05

最满意答案

  • 假设您的第一个回购名称是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 is repo-2. Now go to both repo-1 and repo-2 then checkout master 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.

相关问答

更多