Why does Git say my master branch is “already up to date” even though it is not?

前端 未结 7 1504
甜味超标
甜味超标 2021-01-29 17:17

Basic Problem

I just deleted ALL the code from a file in my project and committed the change to my local git (on purpose). I did

git pull upstream mas         


        
相关标签:
7条回答
  • 2021-01-29 17:55

    I had the same problem as you.

    I did git status git fetch git pull, but my branch was still behind to origin. I had folders and files pushed to remote and I saw the files on the web, but on my local they were missing.

    Finally, these commands updated all the files and folders on my local:

    git fetch --all
    git reset --hard origin/master 
    

    or if you want a branch

    git checkout your_branch_name_here
    git reset --hard origin/your_branch_name_here
    
    0 讨论(0)
  • 2021-01-29 17:55

    Just a friendly reminder if you have files locally that aren't in github and yet your git status says

    Your branch is up to date with 'origin/master'. nothing to commit, working tree clean

    It can happen if the files are in .gitignore

    Try running

    cat .gitignore 
    

    and seeing if these files show up there. That would explain why git doesn't want to move them to the remote.

    0 讨论(0)
  • 2021-01-29 17:56

    As the other posters say, pull merges changes from upstream into your repository. If you want to replace what is in your repository with what is in upstream, you have several options. Off the cuff, I'd go with

    git checkout HEAD^1  # Get off your repo's master.. doesn't matter where you go, so just go back one commit
    git branch -d master  # Delete your repo's master branch
    git checkout -t upstream/master  # Check out upstream's master into a local tracking branch of the same name
    
    0 讨论(0)
  • 2021-01-29 17:58

    The top answer is much better in terms of breadth and depth of information given, but it seems like if you wanted your problem fixed almost immediately, and don't mind trodding on some of the basic principles of version control, you could ...

    1. Switch to master

      $ git checkout upstream master
      
    2. Delete your unwanted branch. (Note: it must be have the -D, instead of the normal -d flag because your branch is many commits ahead of the master.)

      $ git branch -d <branch_name>
      
    3. Create a new branch

      $ git checkout -b <new_branch_name>
      
    0 讨论(0)
  • 2021-01-29 18:00

    Any changes you commit, like deleting all your project files, will still be in place after a pull. All a pull does is merge the latest changes from somewhere else into your own branch, and if your branch has deleted everything, then at best you'll get merge conflicts when upstream changes affect files you've deleted. So, in short, yes everything is up to date.

    If you describe what outcome you'd like to have instead of "all files deleted", maybe someone can suggest an appropriate course of action.

    Update:

    GET THE MOST RECENT OF THE CODE ON MY SYSTEM

    What you don't seem to understand is that you already have the most recent code, which is yours. If what you really want is to see the most recent of someone else's work that's on the master branch, just do:

    git fetch upstream
    git checkout upstream/master
    

    Note that this won't leave you in a position to immediately (re)start your own work. If you need to know how to undo something you've done or otherwise revert changes you or someone else have made, then please provide details. Also, consider reading up on what version control is for, since you seem to misunderstand its basic purpose.

    0 讨论(0)
  • 2021-01-29 18:13

    While none of these answers worked for me, I was able to fix the issue using the following command.

    git fetch origin

    This did a trick for me.

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