Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove a file from pull request/commit?

Tags:

git

My gitignore file looks like this:

# Ignore bundler config.
 /.bundle

# Ignore all logfiles and tempfiles.
/log/*
!/log/.keep
/tmp
coverage/
public/system/
.DS_Store
.env
logfile
development.log

For whatever reason I keep ending up with my development.log file present in my commits and in pull requests. Right now I have an open pull request with the full development.log file present. How do I remove it?

I've tried the following:

  1. git reset HEAD^ app/log/development.log
  2. git commit --amend --no-edit
  3. git push

End up with The current branch resource has no upstream branch. To push the current branch set the remote as upstream, use git push --set-upstream origin resource. I do that and then I check my PR and the file is still there because clearly it's a no-edit.

I've also tried

  1. git log, found the commit with the file
  2. git reset --soft commit
  3. git push

The problem here is that the file is present locally, and should be, but I want it stripped from the PR.

How do I remove a file from a pull request but not remove it locally?

like image 339
Jake Avatar asked Sep 13 '26 17:09

Jake


1 Answers

First remove the log file from the git index while leaving it on disk with the --cached option:

git rm --cached log/development.log

Then check in the file removal:

git commit -m 'remove development log'
like image 170
infused Avatar answered Sep 16 '26 08:09

infused



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!