Push changes to github without pull

I have a stupid situation. I have developed a project that was been developed by another developers. I have sent my sources to the previous developers to make changes in their sources. But they said that they have never work with git. So they have added changes to the projects and it is actual version right now. But it is not under version control code.

So I already have commits on the github and I need to push this new version.

What I did:

  • git init
  • git remote add origin
  • git add .
  • git push origin master
  • But here is an problem, I can't push new changes before updating local repo of course. But if I update my repo it will return back all files that the previous developers have deleted.

    My question: how to push current version without pulling data from git.

    I know comic situation, but I need help here.

    Thanks


    It seems like the other people worked on your project outside version control ie bare files and folder.

    I would suggest you to clone the repo, copy ( and hence replace ) the cloned content with the new content, commit and push. git init etc you are trying create completely new repos, which is not what you want.


    You can do a forced push.

    git push -f origin branch_name
    

    The forced push will erase all commit history of the remote repository's branch, and replace it to your branch.

    Check answers for doing forced pushes here. Forced push can have unintended consequences though, so check for the same.

    Edit

    The forced push will be an incorrect way to push stuff in your case, since you already have previous commits on github, and this will erase the commit history for previous commits.

    Hence, to preserve your commit history, you can do the following things

    Remove all the files from git repository, and then add the new files here, and then commit the updated files

    git rm -rf .
    cp -r path/to/updated/code/* .
    git add .
    

    Doing a git status now will tell you which all files the other developers have modified, and a git diff to see what all modifications are there.

    If a file has remain unchanged, then git rm and git add will nullify the effect of each other.

    The files which those developers deleted remain deleted since you ran the git rm for them but no git add .

    Once you are satisfied that these indeed are the changes, you can commit using

    git commit -m "Merged new code"
    

    Potential gotchas

  • Only the file mode has changed (755 <=> 644) - depending on what code the other developers sent you
  • You will lose your .gitignore file with git rm -rf . (and similarly .gitattributes and other such files). Reset HEAD for each such files using git reset HEAD .gitignore before the commit.
  • Different line terminating characters (in case different development environments are being used), So check for them appropriately.

  • You can try git stash , which will take a snapshot of your work tree. Then you can pull the changes from github. From man git stash :

    Use git stash when you want to record the current state of the working directory and the index, but want to go back to a clean working directory. The command saves your local modifications away and reverts the working directory to match the HEAD commit.

    So:

    git stash
    git pull me@github.com/myrepo.git
    git stash apply
    git commit -a
    
    链接地址: http://www.djcxy.com/p/49028.html

    上一篇: Git:如何重新包装所有松散的提交

    下一篇: 无需拉动即可将更改推送至github