git: How do I get the latest version of my code?

前端 未结 11 1132
野性不改
野性不改 2021-01-29 17:08

I\'m using Git 1.7.4.1. I want to get the latest version of my code from the repository, but I\'m getting errors ...

$ git pull
….
M   selenium/ant/build.proper         


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

    If you just want to throw away everything in your working folder (eg the results of a failed or aborted merge) and revert to a clean previous commit, do a git reset --hard.

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

    If you don't care about any local changes (including untracked or generated files or subrepositories which just happen to be here) and just want a copy from the repo:

    git reset --hard HEAD
    git clean -xffd
    git pull
    

    Again, this will nuke any changes you've made locally so use carefully. Think about rm -Rf when doing this.

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

    Case 1: Don’t care about local changes

    • Solution 1: Get the latest code and reset the code

      git fetch origin
      git reset --hard origin/[tag/branch/commit-id usually: master]
      
    • Solution 2: Delete the folder and clone again :D

      rm -rf [project_folder]
      git clone [remote_repo]
      

    Case 2: Care about local changes

    • Solution 1: no conflicts with new-online version

      git fetch origin
      git status
      

      will report something like:

      Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
      

      Then get the latest version

      git pull
      
    • Solution 2: conflicts with new-online version

      git fetch origin
      git status
      

      will report something like:

      error: Your local changes to the following files would be overwritten by merge:
          file_name
      Please, commit your changes or stash them before you can merge.
      Aborting
      

      Commit your local changes

      git add .
      git commit -m ‘Commit msg’
      

      Try to get the changes (will fail)

      git pull
      

      will report something like:

      Pull is not possible because you have unmerged files.
      Please, fix them up in the work tree, and then use 'git add/rm <file>'
      as appropriate to mark resolution, or use 'git commit -a'.
      

      Open the conflict file and fix the conflict. Then:

      git add .
      git commit -m ‘Fix conflicts’
      git pull
      

      will report something like:

      Already up-to-date.
      

    More info: How do I use 'git reset --hard HEAD' to revert to a previous commit?

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

    By Running this command you'll get the most recent tag that usually is the version of your project:

    git describe --abbrev=0 --tags
    
    0 讨论(0)
  • 2021-01-29 17:41

    try this code

    cd /go/to/path
    git pull origin master
    
    0 讨论(0)
  • 2021-01-29 17:42

    If you are using Git GUI, first fetch then merge.

    Fetch via Remote menu >> Fetch >> Origin. Merge via Merge menu >> Merge Local.

    The following dialog appears.

    Select the tracking branch radio button (also by default selected), leave the yellow box empty and press merge and this should update the files.

    I had already reverted some local changes before doing these steps since I wanted to discard those anyways so I don't have to eliminate via merge later.

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