代码之家  ›  专栏  ›  技术社区  ›  dorien

如何将一个全新的目录从一个未克隆的文件夹上传到git

  •  0
  • dorien  · 技术社区  · 9 年前

    我使用git init创建了一个空的存储库。如果我克隆远程回购,那么我的本地更改将被覆盖,对吗?

    我想我需要做两件事:

    • 我的更改
    • 上载更改

    3 回复  |  直到 9 年前
        1
  •  1
  •   zigarn    9 年前
    cd /path/to/not_cloned/folder
    git init
    git remote add origin BITBUCKET_URL
    git fetch
    git reset --soft origin/master # This will move your current 'master' branch to the same commit as 'origin/master'
    git status
    # You should see all files from repository as deleted and all new files as untracked
    git add .
    git commit --message "New structure"
    git push origin master
    
        2
  •  0
  •   dorien    9 年前

    添加回购:

    git init
    git remote set-url origin git@bitbucket.org:username/project.git
    

    git add ./*
    git commit
    git push --force -u origin master
    
        3
  •  0
  •   running.t    9 年前

    因此,您在本地回购中进行了初始提交,所有其他更改都未被限制,您希望用您的本地更改替换origin,对吗?如果不想覆盖bitbucket历史,可以:

    1. 为更改创建本地分支 git checkout -b your_branch
    2. 向该分支添加并提交所有更改 git add ./* git commit
    3. git chekout master (假设您的主机与bitbucket主机同步)
    4. git merge your_branch