Noob question about Git:
I made a few minor changes on my server directly (without using Git). I just opened cPanel and changed the names of a few image files and deleted a few unused images.
Then I went back to my code editor and made changes in a few files. But I can’t push to master now, because Git says, “! [remote rejected] master -> master (Working directory has unstaged changes)”
I’m not sure how to get around this. I wouldn’t mind a solution that undoes the changes I made directly to the server files. I wouldn’t mind a solution that loses the changes I made to my text in the editor either. They were all very minor. I just want them back in sync!
I tried to create a new branch with “git checkout -b example” and did “git pull” into that branch. That went fine. I can push too, and I can “git checkout master” and then “git merge example” and that seems successful. But then when I “git checkout master” and then “git push origin master” it gives me the error message.
I appreciate any advice you can give!
3
Answers
To clear the recent changes and go back to the last state (last commit), just make sure you’re at the top-level of your repo, and do
Another way to clear these changes is
git stash
which would put these changes in an isolated branch, just in case you regret having wiped them earlier.A simple solution for your case is to:
rm -r *
git reset --hard
orgit checkout -- .
Having step 2 is just in case your future changes have files in conflict.
Step 3 resets every tracked files on your working directory back to the current branch’s version.
If you would like to keep the changes, you can perform
git add .
and thengit commit
on your server, and then on your machine dogit pull
, which should trigger a merge. Then you can push as usual.Sometimes file changes could be file permissions.
You can check which with.
git add -p .