search

Home  >  Q&A  >  body text

git - How to update the same file in different branches?

For example, branch master and branch dev have a file file.ext at the same time. I updated (commit & push) this file on branch dev. How can I update the file on branch master when my colleagues update?

黄舟黄舟2769 days ago699

reply all(5)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-05-02 09:25:24

    The solution I gave is not automatic and requires manual operation. It should not be possible to automatically update a single file
    1: First switch to the master branch:

    git checkout master
    

    2: Take out the file.ext file on the dev branch

    git checkout dev -- file.ext
    

    3: Then submit file.ext to the master branch

    git add file.ext
    git commit -m 'update file.ext from dev'
    

    The above is the whole process

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-02 09:25:24

    Switch to the master branch, then merge dev and push it

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-02 09:25:24

    If this submission only contains this one required file, then the colleague can just use master to pull origin dev

    If there are multiple commits on origin, and the colleague’s master only needs one of them, then the colleague will first pull origin dev on dev, and then return to master to cherrypick the commit(s) needed on dev

    If this target file is mixed in a certain submission (that is, there is more than one change in the submission, but the colleague’s master only needs this one file), then just like @brucemj said, manually checkout

    reply
    0
  • 阿神

    阿神2017-05-02 09:25:24

    There is a way. First push the content you want to update. Then switch the branch and then right-click replace width and select branch, tag, or reference to select the branch content you just submitted. It will be ok

    This is the eclipse .git plug-in

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-02 09:25:24

    • git checkout master

    • git cherry-pick commit-id

    reply
    0
  • Cancelreply