Pull Request, ignore some file changes
Asked Answered
B

4

64

When I do a Pull Request on GitHub (against master branch), can we ignore some file changes, like

  • we have one file named 'fileA' in branch 'release', and we have the same file in 'master', but we do some changes in 'fileA' in branch 'release'
  • when we do a Pull Request, is there any way we can ignore the changes in 'fileA', do not let that merge into 'master'.
Baillie answered 24/2, 2015 at 18:10 Comment(1)
No. Create branch without modifications of fileATorry
H
44

You can't ignore some files from a pull request selectively. Two workarounds for this can be -

First -

  • Create a new branch from 'release'
  • Replace the non-required files from 'master'
  • Create pull request from this new branch

Second -

  • Create a new branch from 'master'
  • Put changes of required files from 'release'
  • Create pull request from this new branch

Any of this method will work. Which will be easier depends upon how many files are to be included / excluded.

Hubbard answered 24/2, 2015 at 18:37 Comment(0)
H
16

As mentioned in https://mcmap.net/q/301176/-pull-request-ignore-some-file-changes, it is not possible to exclude files in a Pull-Request, and the alternatives which have been proposed also work.

But there is a simpler solution to it. Here I am considering staging as my target and dev as my source

root
|-- src
|   -- app.py
|-- .gitignore
|-- settings.py
|-- requirements.txt

Let's say, I would want to ignore the settings.py file from being merged

  • First move to the target branch (the branch to which you want to merge the changes)
    git checkout staging
    
  • Then you can use the git checkout command to selective pick the files you want to merge
    git checkout dev src/
    
  • This will only merge the files changed inside src/ folder

    NOTE: You can also do it selectively for each file.

  • Then push to remote repository

    git push origin staging
    

But this solution is useful only if the files to be excluded is small.

Hayott answered 29/4, 2020 at 15:30 Comment(0)
K
2

Create branch with last commit you agree with:

git branch my-branch <sha>
git checkout my-branch

Select commits you want to pull request as patches:

git format-patch -10 <sha> --stdout > 0001-last-10-commits.patch

Apply patches:

git am < 0001-last-10-commits.patch

Your commits will be as they was. You can git push -u origin my-branch immediately.

Kolnick answered 14/10, 2016 at 15:46 Comment(0)
A
1

My scenario was: I am using CI/CD in AWS and the pipeline reads from buildspec.yml. In the dev pipeline I need a specific Cloudfront id written in buildspec.yml and in the main pipeline the Cloudfront id changes. My steps to prevent changing this file in a Github PR were:

  1. Backup the content of the files in another external file
  2. Delete the buildspec.yml file
  3. Add the buildspec.yml file in the .gitignore file
  4. Push these changes
  5. Create a new buildspec.yml from the Github UI directly. Set the values corresponding from each branch (dev and main)

This way the .gitignore ignores the different versions of buildspec.yml in dev and main. In every PR, I get the changes of all files but the buildspec.yml does not appear. It is worth mentioning that if I make a change in the buildspec.yml file, git will recognize that change and make it commitable (I am not sure why).

I hope this helps anyone :)

Abidjan answered 30/1, 2024 at 23:52 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.