【问题标题】:Replace Files in Git Repository?替换 Git 存储库中的文件?
【发布时间】:2016-06-12 23:10:37
【问题描述】:

我在 gitlab 的 git 存储库中有一个工作应用程序。为了找出一个错误,我在一个新的应用程序目录中逐个功能地重建了应用程序。错误消失了,现在我想用新应用程序目录中的文件更新存储库中的文件。这样做的正确方法是什么?

【问题讨论】:

    标签: git gitlab


    【解决方案1】:

    在你的目录中

    1.新建git仓库:

    git init
    

    2.将您的远程存储库添加到上游:

    git remote add origin git@....... 
    

    -你的仓库git地址

    3.Checkout 远程仓库使用的分支:

    git checkout -b master (or any other branch that holds your code)
    

    4.添加并提交您的更改:

    git add dir/file.py (or php or whatever)
    
    git commit -m 'bug fixed'
    

    4.拉取远程更改:

    git pull origin master   (or whatever other branch is used)
    

    5.将您的更改推送到远程源:

    git push origin master   (or any other branch you checked out)
    

    此时您的代码应该在存储库中

    【讨论】:

    • 当我运行git checkout master 时出现错误,“pathspec 'master' 与 git 已知的任何文件都不匹配。”,即使 gitlab 似乎显示当前路径已命名“主人”。
    • git checkout -b master 应该在您创建新的分支 master 时修复它。您可以运行 git status 并查看您确实在 master 上。如果您从中提取的分支具有不同的名称,您可以以相同的方式到达那里 git checkout branchname
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    • 2021-08-18
    • 1970-01-01
    • 2016-05-05
    • 2012-10-03
    • 2020-03-01
    相关资源
    最近更新 更多