I have just made a commit of some changes to about 4 files. After sending this commit to remote, I have noticed that a couple of extra files were included with this commit. How can I
- Make sure that the remote does not contain changes in these files.
- Make sure that the production server also does not contain these files (I already did a pull there)
- Have the original changes to these two files in my local working tree.
In other words, I would like to revert changes as far as these files are concerned.
In case it matters, this is the latest commit. There has not been any after this one. Also, these were newly created files, not files that were being changed.
Edit:
When I do git show
, I can see that the files I actually wanted in the commit have something like:
diff --git a/mysite/apps/common/models.py b/mysite/apps/common/models.py
index 9d86707..1a53b94 100755
--- a/mysite/apps/common/models.py
b/mysite/apps/common/models.py
whereas the files that were somehow wrongly included have
diff --git a/mysite/apps/payment/migrations/0011_auto_20221006_1850.py b/mysite/apps/payment/migrations/0011_auto_20221006_1850.py
new file mode 100644
index 0000000..26320ba
--- /dev/null
b/mysite/apps/payment/migrations/0011_auto_20221006_1850.py
Where did they come from?
CodePudding user response:
Do not overcomplicate it by asking to keep it in your working tree. If you do a revert (and lose it on the working tree) and push so that it gets corrected where you need it now), then you can find out how to git it back the way you want, which is done (after a revert) with:
git checkout HEAD~ -- file1 file2
And then you can commit that with the right commit message, the right files and stuff.
By the way, it's not like what you asked for can't be done... it can be done, but I do not see why you want to do it that way when stuff is in production already.
CodePudding user response:
Well! you can't keep them in the commit if you don't want to be in the remote/production server. If you think there are some files added to your last commit by mistake then you can revert back to last staging state by following:
git reset --soft HEAD^
This will revert your last commit and move your head to previous commit while keeping all the files in staging. From there you can remove unwanted files by git reset <file>
. Hope this helps!!!