What to do when git won't pull
2014-05-21 19:11
501 查看
原文地址:http://nbviewer.ipython.org/gist/choldgraf/6359961
Say you've got a repository on your local computer that you sync to a remote repository that your whole lab shares.
You do some work on Monday, and push it to the repository.
First, you sync with the remote repository
In [34]:
Then, you create a file and add it to be committed.
In [35]:
Now, you commit and push this to the repository. This is the right way of doing things! Good job on Monday!
In [36]:
Then, you arrive on Tuesday morning, and realize that you didn't name the file correctly...
so you change it, and you also change the text
In [37]:
then you realize "whoops, I forgot to synchronize my code to the repository".
This might be important because another lab member was changing some code the night before.
You stop writing code, move to the command line, and quickly try a git pull.
In [38]:
Whoops! You just broke git!
Ultimately, git wants to make sure that nobody unintentionally overwrites their own work or the work of others.
In this case, person A made changes to their local repository, but they didn't sync person B's changes first.
So, if person A had sync'ed, it would have overwritten their own changes.
Git assumes you don't want this to happen, so it returns an error rather than overwriting stuff for you.
It's important to know that whenever you "git pull", git is really doing two things:
A "git fetch", which retrieves the latest copy of the remote repository and stores it somewhere to be used later
A "git merge", which tries to merge that fetched repository with the branch you're currently on
In this case, the "merge" noted that there were conflicts between the remote repository and your own
Luckily, fixing this problem is as easy as performing the abovementioned commands independently of one another
First we fetch the latest copy of the remote repository. Note that this copy will be called "origin/master", corresponding to the "master" branch of the remote repository referenced by "origin"
In [39]:
Now we need to commit our changes so that git can properly compare them
In [27]:
Now, try to merge...a conflict will come up, so we will use a mergetool
In []:
Now, we have the merge completed, we need only commit the merge and push to the repository
In []:
Note - this often means you'll need to use something like a mergetool. I'm going to assume you know how to use one here.
Now, your local repository is synced with the remote repo, and we can continue our work.
In [31]:
In [32]:
In [33]:
In [28]:
Say you've got a repository on your local computer that you sync to a remote repository that your whole lab shares.
You do some work on Monday, and push it to the repository.
First, you sync with the remote repository
In [34]:
Then, you create a file and add it to be committed.
In [35]:
Now, you commit and push this to the repository. This is the right way of doing things! Good job on Monday!
In [36]:
Then, you arrive on Tuesday morning, and realize that you didn't name the file correctly...
so you change it, and you also change the text
In [37]:
then you realize "whoops, I forgot to synchronize my code to the repository".
This might be important because another lab member was changing some code the night before.
You stop writing code, move to the command line, and quickly try a git pull.
In [38]:
Whoops! You just broke git!
Ultimately, git wants to make sure that nobody unintentionally overwrites their own work or the work of others.
In this case, person A made changes to their local repository, but they didn't sync person B's changes first.
So, if person A had sync'ed, it would have overwritten their own changes.
Git assumes you don't want this to happen, so it returns an error rather than overwriting stuff for you.
It's important to know that whenever you "git pull", git is really doing two things:
A "git fetch", which retrieves the latest copy of the remote repository and stores it somewhere to be used later
A "git merge", which tries to merge that fetched repository with the branch you're currently on
In this case, the "merge" noted that there were conflicts between the remote repository and your own
Luckily, fixing this problem is as easy as performing the abovementioned commands independently of one another
First we fetch the latest copy of the remote repository. Note that this copy will be called "origin/master", corresponding to the "master" branch of the remote repository referenced by "origin"
In [39]:
Now we need to commit our changes so that git can properly compare them
In [27]:
Now, try to merge...a conflict will come up, so we will use a mergetool
In []:
Now, we have the merge completed, we need only commit the merge and push to the repository
In []:
Note - this often means you'll need to use something like a mergetool. I'm going to assume you know how to use one here.
Now, your local repository is synced with the remote repo, and we can continue our work.
In [31]:
In [32]:
In [33]:
In [28]:
What to do when git won't pull
Monday
Say you've got a repository on your local computer that you sync to a remote repository that your whole lab shares.You do some work on Monday, and push it to the repository.
Here's your (correct) workflow for Monday.
First, you sync with the remote repositoryIn [34]:
%%bash cd myRepo/ ls git pull
README.md Already up-to-date.
Then, you create a file and add it to be committed.
In [35]:
%%bash cd myRepo/ touch nowimworking.txt echo "Look at me. Work work work" > nowimworking.txt git add -A git status
# On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: nowimworking.txt #
Now, you commit and push this to the repository. This is the right way of doing things! Good job on Monday!
In [36]:
%%bash cd myRepo/ git commit -m "I've committed all of this work!" git push
[master 6862b4b] I've committed all of this work! 1 file changed, 1 insertion(+) create mode 100644 nowimworking.txt
To https://github.com/choldgraf/git_wont_pull 3d93d42..6862b4b master -> master
While you were sleeping, your co-worker is busy at work!
Tuesday morning
Then, you arrive on Tuesday morning, and realize that you didn't name the file correctly...so you change it, and you also change the text
In [37]:
%%bash cd myRepo/ echo "Whoops, I forgot to change something important" > nowimworking.txt cat nowimworking.txt
Whoops, I forgot to change something important
then you realize "whoops, I forgot to synchronize my code to the repository".
This might be important because another lab member was changing some code the night before.
You stop writing code, move to the command line, and quickly try a git pull.
In [38]:
%%bash cd myRepo/ git pull
Updating 6862b4b..3984193
From https://github.com/choldgraf/git_wont_pull 6862b4b..3984193 master -> origin/master error: Your local changes to the following files would be overwritten by merge: nowimworking.txt Please, commit your changes or stash them before you can merge. Aborting
Whoops! You just broke git!
So, what just happened?
Ultimately, git wants to make sure that nobody unintentionally overwrites their own work or the work of others.In this case, person A made changes to their local repository, but they didn't sync person B's changes first.
So, if person A had sync'ed, it would have overwritten their own changes.
Git assumes you don't want this to happen, so it returns an error rather than overwriting stuff for you.
How do get around this?
It's important to know that whenever you "git pull", git is really doing two things:A "git fetch", which retrieves the latest copy of the remote repository and stores it somewhere to be used later
A "git merge", which tries to merge that fetched repository with the branch you're currently on
In this case, the "merge" noted that there were conflicts between the remote repository and your own
Luckily, fixing this problem is as easy as performing the abovementioned commands independently of one another
So here's how you fix this:
First we fetch the latest copy of the remote repository. Note that this copy will be called "origin/master", corresponding to the "master" branch of the remote repository referenced by "origin"In [39]:
%%bash cd myRepo/ git fetch origin
Now we need to commit our changes so that git can properly compare them
In [27]:
%%bash git add -A git commit -m "I'm committing my changes so that I can merge with the remote repository"
usage: git diff [--no-index] <path> <path>
Now, try to merge...a conflict will come up, so we will use a mergetool
In []:
%%bash git merge origin/master git mergetool
Now, we have the merge completed, we need only commit the merge and push to the repository
In []:
%%bash git commit -m "Successfully merged" git push
Note - this often means you'll need to use something like a mergetool. I'm going to assume you know how to use one here.
Now, your local repository is synced with the remote repo, and we can continue our work.
The End
To delete the git repository and re-initialize a new one!
In [31]:%%bash rm -r myRepo/ rm -r ../person2/myRepo2/
Create my repo
In [32]:%%bash git clone https://github.com/choldgraf/git_wont_pull myRepo cd myRepo git status
Cloning into 'myRepo'... # On branch master nothing to commit (working directory clean)
Create the second (your friend's) repo
In [33]:%%bash git clone http://github.com/choldgraf/git_wont_pull ../person2/myRepo2 cd ../person2/myRepo2 git status
Cloning into '../person2/myRepo2'... # On branch master nothing to commit (working directory clean)
This totally resets the git repository back to its original commit
In [28]:%%bash cd myRepo/ git reset --hard 3d93d42d5230ac50677d847350c3c455fd792c94 git push -f
HEAD is now at 3d93d42 first commit
To https://github.com/choldgraf/git_wont_pull + c42e00a...3d93d42 master -> master (forced update)
What to do when git won't pull
Monday
Say you've got a repository on your local computer that you sync to a remote repository that your whole lab shares.You do some work on Monday, and push it to the repository.
Here's your (correct) workflow for Monday.
First, you sync with the remote repositoryIn [34]:
%%bash cd myRepo/ ls git pull
README.md Already up-to-date.
Then, you create a file and add it to be committed.
In [35]:
%%bash cd myRepo/ touch nowimworking.txt echo "Look at me. Work work work" > nowimworking.txt git add -A git status
# On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: nowimworking.txt #
Now, you commit and push this to the repository. This is the right way of doing things! Good job on Monday!
In [36]:
%%bash cd myRepo/ git commit -m "I've committed all of this work!" git push
[master 6862b4b] I've committed all of this work! 1 file changed, 1 insertion(+) create mode 100644 nowimworking.txt
To https://github.com/choldgraf/git_wont_pull 3d93d42..6862b4b master -> master
While you were sleeping, your co-worker is busy at work!
Tuesday morning
Then, you arrive on Tuesday morning, and realize that you didn't name the file correctly...so you change it, and you also change the text
In [37]:
%%bash cd myRepo/ echo "Whoops, I forgot to change something important" > nowimworking.txt cat nowimworking.txt
Whoops, I forgot to change something important
then you realize "whoops, I forgot to synchronize my code to the repository".
This might be important because another lab member was changing some code the night before.
You stop writing code, move to the command line, and quickly try a git pull.
In [38]:
%%bash cd myRepo/ git pull
Updating 6862b4b..3984193
From https://github.com/choldgraf/git_wont_pull 6862b4b..3984193 master -> origin/master error: Your local changes to the following files would be overwritten by merge: nowimworking.txt Please, commit your changes or stash them before you can merge. Aborting
Whoops! You just broke git!
So, what just happened?
Ultimately, git wants to make sure that nobody unintentionally overwrites their own work or the work of others.In this case, person A made changes to their local repository, but they didn't sync person B's changes first.
So, if person A had sync'ed, it would have overwritten their own changes.
Git assumes you don't want this to happen, so it returns an error rather than overwriting stuff for you.
How do get around this?
It's important to know that whenever you "git pull", git is really doing two things:A "git fetch", which retrieves the latest copy of the remote repository and stores it somewhere to be used later
A "git merge", which tries to merge that fetched repository with the branch you're currently on
In this case, the "merge" noted that there were conflicts between the remote repository and your own
Luckily, fixing this problem is as easy as performing the abovementioned commands independently of one another
So here's how you fix this:
First we fetch the latest copy of the remote repository. Note that this copy will be called "origin/master", corresponding to the "master" branch of the remote repository referenced by "origin"In [39]:
%%bash cd myRepo/ git fetch origin
Now we need to commit our changes so that git can properly compare them
In [27]:
%%bash git add -A git commit -m "I'm committing my changes so that I can merge with the remote repository"
usage: git diff [--no-index] <path> <path>
Now, try to merge...a conflict will come up, so we will use a mergetool
In []:
%%bash git merge origin/master git mergetool
Now, we have the merge completed, we need only commit the merge and push to the repository
In []:
%%bash git commit -m "Successfully merged" git push
Note - this often means you'll need to use something like a mergetool. I'm going to assume you know how to use one here.
Now, your local repository is synced with the remote repo, and we can continue our work.
The End
To delete the git repository and re-initialize a new one!
In [31]:%%bash rm -r myRepo/ rm -r ../person2/myRepo2/
Create my repo
In [32]:%%bash git clone https://github.com/choldgraf/git_wont_pull myRepo cd myRepo git status
Cloning into 'myRepo'... # On branch master nothing to commit (working directory clean)
Create the second (your friend's) repo
In [33]:%%bash git clone http://github.com/choldgraf/git_wont_pull ../person2/myRepo2 cd ../person2/myRepo2 git status
Cloning into '../person2/myRepo2'... # On branch master nothing to commit (working directory clean)
This totally resets the git repository back to its original commit
In [28]:%%bash cd myRepo/ git reset --hard 3d93d42d5230ac50677d847350c3c455fd792c94 git push -f
HEAD is now at 3d93d42 first commit
To https://github.com/choldgraf/git_wont_pull + c42e00a...3d93d42 master -> master (forced update)
相关文章推荐
- What to Do When You Have to Work with Someone You Don't Like
- What to do when the Chinese Characters are messed up when extracting from zip archive?
- What To Do When The Boss Begs You To Stay
- Disaster Recovery: What to do when the SA account password is lost in SQL Server 2005
- What To Do and Not To Do When 'shutdown immediate' Hangs [ID 375935.1]
- Git push won't do anything (Everything up-to-date)
- What to do when wps failed to install on Ubuntu?
- What To Do When The Boss Begs You To Stay
- what-to-do-when-nexus-returns-401
- ccah-500 第25题 what do you need to do when adding a new slave node to cluster
- git fail, and what to do????
- What i want to do.
- do what you want to do and be youself
- 最简单,最自由的开源许可!DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
- What to build when...
- what would you do if you had only one day left to live?
- 面试题:What will happen when you attempt to compile and run the following code
- 需求调研中的5W+1H定律(WHY、WHAT、WHO、WHEN、WHERE + HOW TO ACCOMPLISH THE SYSTEM)
- what does Intel ioat do to accelate network IO
- What i want to do(2)