Reputation: 29
I created a .env
file with the following line SKIP_PREFLIGHT_CHECK=true
within my react app folder to get the app started on my localhost using npm run start
. My 5 out of 6 commits contains the .env
file. My last commit is the one where I deleted the .env file. i tried to push just that commit without .env
file, yet it still shows the same error
todo1\t05-practical-work\backend>git push
Enumerating objects: 57, done.
Counting objects: 100% (51/51), done.
Delta compression using up to 8 threads
Compressing objects: 100% (31/31), done.
Writing objects: 100% (33/33), 6.58 KiB | 1.10 MiB/s, done.
Total 33 (delta 24), reused 0 (delta 0), pack-reused 0
remote: GitLab: File name frontend/.env was prohibited by the pattern ".env$".
To https://gitlab.tamk.cloud/courses/web-software-production-5g00dm04/3003/t05-practical-work.git
! [remote rejected] develop -> develop (pre-receive hook declined)
error: failed to push some refs to 'https://gitlab.tamk.cloud/courses/web-software-production-5g00dm04/3003/t05-practical-work.git'
How can I fix it without losing my current branch and code?
Upvotes: 1
Views: 385
Reputation: 489478
You cannot push a commit without pushing its entire ancestry.
If you've set up your receiving repository to reject certain commits, you can't push those commits. Since the sixth commit requires the earlier five commits that you already forbade to yourself, you can't push the sixth commit because you told yourself that this was forbidden.
Your options are:
To exercise the second option, consider taking the six commits and producing, from them, one new and different commit that doesn't do the forbidden thing. This one new-and-different commit adds on to commits that are already accepted, and since this one commit won't do the thing your forbade to yourself, you won't reject your own commit.
To achieve this, the easy way is to use git reset --soft HEAD~6
followed by git commit
, or git rebase -i HEAD~6
and turn five of the six commits into squash and/or fixup commits.
Upvotes: 1