How can I associate local unversioned code to git remote repository?

前端 未结 4 978
别跟我提以往
别跟我提以往 2020-12-31 00:24

I need to associate a clean unversioned code to an existing git remote repository.

I explain better my situation. My project is moved from svn to git. I have a svn

相关标签:
4条回答
  • 2020-12-31 01:05

    I would commit your working directory to ensure that it exists in history before fetching. (ensure you are in the projects root folder)

    git init
    git add -A
    git commit -m "my latest'
    

    now we have it

    git remote add origin url-to-your-remote
    git fetch origin
    

    now we have the history from the remote

    git reset origin/master
    

    now our current commit is the latest from the remote

    git add -A
    git commit -m "Committed my state"
    

    now we use our current working directory as the snapshot for the next commit.

    git push -u origin master
    

    push up your changes and track the branch.

    the key is the reset command with no --hard option. It keeps your working folder the same while pointing the branch to what you got from the remote.

    0 讨论(0)
  • 2020-12-31 01:07

    Would the following work? I tried it on one of my projects and it worked.

    1) Clone the git repository to a location different from the directory that contains the unversioned code.

    2) Copy the .git folder from the directory created as a result of (1) to the directory that contains the unversioned code.

    This effectively achieved for me what Adam Dymitruk steps in his answer above.

    0 讨论(0)
  • 2020-12-31 01:08

    Ok, I post the right answer for my question based on Adam Dymitruk and Eugene Sajine answers. Thanks everyone for the support :)

    • First of all, remove all .svn directories in working copy directory;
    • initialize new git repository in the working copy directory

      cd /path/to/my/project
      git init
      
    • add git remote repository and fetch it

      git remote add origin url-to-your-remote
      git fetch origin
      
    • reset working copy to remote repository

      git reset --hard origin/master
      

    At the end local repository will be synchronized with remote repository.

    0 讨论(0)
  • 2020-12-31 01:17

    If you really mean what you're saying then the sequence will be:

    cd {your-project}
    git init
    git remote add {remote_name} {address}
    git fetch {remote_name}
    

    Then you can create a local branch from one of the branches that the remote has for example:

    git branch master {remote_name}/master
    

    and then you can add your code:

    git add {files}
    

    or

    git add .
    git commit
    

    UPDATE:

    The OP specifies that the code in question is old and there is nothing to commit, therefore it seems that the whole situation is overcomplicated for no reason. OP just should clone the new repository and be done with it. Ignore configurations should be redone in accordance to the project policies (either .gitingore is stored in the repo or not and etc.)

    0 讨论(0)
提交回复
热议问题