简体   繁体   中英

git pull changes from remote repo keeping the changes in local file

我在本地项目目录中有一个修改后的文件htmlpage.html,我想从bitbucket的远程分支中提取对该文件的更改而不会影响我的本地文件更改

Instead of committing or creating a new branch, simply make sure, as I explain here , to have:

git config --global pull.rebase true
git config --global rebase.autoStash true

From there, any git pull will automatically:

  • stash your local changes
  • update your current branch by replaying your local commits on top of the updated (fetched) remote branch ( pull --rebase )
  • re-apply your stashed changed to your htmlpage.html

Another approach, I detailed here :

git update-index --skip-worktree -- htmlpage.html
# to cancel it:
git update-index --no-skip-worktree -- htmlpage.html

Save a copy of your file first, before testing a git pull : htmlpage.html snould remain unchanged.

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