简体   繁体   中英

How to commit changes on server and pull updates from code repository without conflict?

I pushed latest codes from my GitLab repository. The changes was coming from my local development machine. I've successfully done it using this commands:

git push

to push my latest changes to my GitLab repository. Now I pulled the updates on server but unfortunately it did not happen successfully since I have uncommitted changes from the server.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)

 modified:   .htaccess
 modified:   composer.json
 modified:   composer.lock

Untracked files:
(use "git add <file>..." to include in what will be committed)
php.ini
php_errorlog

These changes makes my git pull failed thus need to commit it first before pulling the updates from GitLab repository. How should we commit it the right way to prevent conflict on server side.

This is actually the scenario:

First I push my changes from local development machine to Gitlab repository. git command git push

Second I pull code updates from Gitlab repository to my server. git command git pull

Third I get conflict due to uncommitted changes in server. Error conflict: after done the second step.

 Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)

 modified:   .htaccess
 modified:   composer.json
 modified:   composer.lock

Untracked files:
(use "git add <file>..." to include in what will be committed)
php.ini
php_errorlog

NOTE: If multiple people are working on the same file, then there is more possibility of getting conflicts. It will be easy to resolve conflicts with Visual Studio Code Editor

Steps to resolve conflicts

  1. Check whether all your change set are correct, validate once and remove /discard all the wanted files which you don't want to commit
  2. Enter the command in current work folder git add.
  3. Then check the staged file with the next command git status and validate once like whether the required file only got staged up.
  4. Then do git stash , which will store your current code with another index
  5. Now do git pull to pull the changes from the server, which will make your current working repository latest with server
  6. Now do git stash pop , this will stash the changes which you have done
  7. Since you have poped out your changes, if any conflict occurs check the changeset if both are needed - do Accept Both , if only your changes needed - do Accept Incoming , if the current changes present in server is needed - Accept Current .
  8. Again check git status , by this you can reverify whether only your changeset is correct
  9. Now you can commit your changes to the server

Hope this would be helpful

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