简体   繁体   中英

How to get latest update from remote repository then add and commit my file later?

The case is I want to get latest update from remote repository, so I do git pull remoteRepository

Unfortunatelly I got conflict

$ git pull live master
git@123.xxx.xxx.xxx's password:
From 123.xxx.xxx.xxx:/home/git/myweb_live
 * branch            master     -> FETCH_HEAD
...
...
Automatic merge failed; fix conflicts and then commit the result.

So now I have this on my git status

On branch master
You have unmerged paths.
(fix conflicts and run "git commit")

Changes to be committed:

        modified:   backend/modules/agent/controllers/file1.php
        modified:   backend/modules/agent/controllers/file2.php
        modified:   backend/modules/agent/controllers/manyfile.php
        modified:   backend/modules/agent/views/agent/file1.php
        modified:   backend/modules/agent/views/agent/manyfile.php

Unmerged paths:
  (use "git add <file>..." to mark resolution)

        both modified:   backend/runtime/debug/index.data
        both modified:   backend/runtime/logs/app.log
        both modified:   backend/runtime/logs/app.log.1
        both modified:   common/component/ScurityHelper.php
        both modified:   common/models/TbCustomer.php

I check git log and the latest commit is still different with remote repository.

How I can get latest from remote repository?

So Later I can add and commit file I working on which currently doesn't appear in above list, then push to remote repository, and in other machine I pull without conflict.

If I git commit with current status, I think it will conflict when I pull from other machine after I git push. Because the above file is not my file where I'm working on. and I want to add my files where I'm working on.

Thanks in advance.

There are several ways to handle your situation.

In order to unstage the entire directory you can use the following command.

Command

git rm --cached -r your_dir

Another solution is to reset hard the files if you no longer needed but this command is very dangerous that it will delete all modified files, you should beware of what files you don't need in order to use reset.

git reset --hard HEAD

or

git reset your_dir

Another method,

try to check out that modified folder, that will checkout the latest files from your master origin by replacing the modified files.

git checkout your_dir

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM