How to make git ignore a directory while merging

前端 未结 2 1709
你的背包
你的背包 2020-12-04 13:27

As interesting and useful as the answer to How to setup a git driver to ignore a folder on merge was, it did not answer the original question which still has me stumped.

2条回答
  •  温柔的废话
    2020-12-04 13:51

    Let's say I'm on branch staging want to merge dev and ignore changes in /build folder:

    git checkout staging
    # go to staging branch
    
    git checkout dev .
    # this checkout dev file changes into staging
    
    git reset HEAD build
    # this remove added file in build folder
    
    git clean -f
    # this drops untracked files we just reseted
    
    git checkout -- .
    # this drops changed files we just rested
    
    git status
    # check is everything ok
    
    git commit -am 'merge dev into branch'
    # create a commit
    
    git merge -s ours dev
    # this create a fake merge to trick Git into thinking that a branch is already merged when doing a merge later on.
    

    this solution is not perfect because it will merge all commits into one. which means cherry-pick some commits may not suitable.

    but it's able to avoid lots of commit in build folder caused by rename/new/delete that need to clean up.

提交回复
热议问题