nus-cs2103-AY2223S2 / forum

12 stars 0 forks source link

When commit the changes, somehow it will automatically convert back to the previous version #320

Open QQH0828 opened 1 year ago

QQH0828 commented 1 year ago

I changed some parts of the codes, and I committed them, it will be okay. But if I change something else and try to commit again, then some of the changes in the previous commit will show on the source tree also, and it somehow converts back to the first version.

For example, if I change a method name from addPerson to addMoney in the Person class, and I commit it, it will reflect in the codes. Then I change something else, maybe UG, and then I want to commit it. I found that sometimes the staged files will also have Person class, and it shows the changes from addMoney to addPerson.

If I did not check properly, these changes are gone, and I need to redo them again. I realized this problem because I think I countered this issue several times. But I still cannot figure out why.

damithc commented 1 year ago

@QQH0828 Just to get more details, are you also using branches while doing these changes?

hingen commented 1 year ago

Probably unlikely, but I've encountered similar issues in the past when I use git on a directory that is being synced by some application (e.g. onedrive, google drive).

seanfirefox commented 1 year ago

2 possible factors to consider other than hingen's response:

  1. Did you possibly leave out your code when doing merge conflicts? It can be easy to miss clicking the :heavy_check_mark: button instead of the :x: button when on Intellij if you do merges by using git merge master from the master from your own fork.
  2. Did you branch out from another branch when calling git checkout -b new-branch instead of master? Not sure if that could result in unintended consequences but making changes on the original branch can cause changes to spill over to newer branch.

Also, did you try to call git log to see if your previous commits have disappeared from your local when you encounter this problem?

Another way is to check your PR and see if the previous commits are registering and if your later commits have somehow deleted your work too.

QQH0828 commented 1 year ago

@QQH0828 Just to get more details, are you also using branches while doing these changes?

Hi, prof. Thank you for reading. Yes, I was using branches while doing these changes. Basically, I was doing the changes in the same branches and did not switch to other branches.

QQH0828 commented 1 year ago

Probably unlikely, but I've encountered similar issues in the past when I use git on a directory that is being synced by some application (e.g. onedrive, google drive).

I also have no idea about it. And I just countered this issue again.

QQH0828 commented 1 year ago

2 possible factors to consider other than hingen's response:

  1. Did you possibly leave out your code when doing merge conflicts? It can be easy to miss clicking the ✔️ button instead of the ❌ button when on Intellij if you do merges by using git merge master from the master from your own fork.
  2. Did you branch out from another branch when calling git checkout -b new-branch instead of master? Not sure if that could result in unintended consequences but making changes on the original branch can cause changes to spill over to newer branch.

Also, did you try to call git log to see if your previous commits have disappeared from your local when you encounter this problem?

Another way is to check your PR and see if the previous commits are registering and if your later commits have somehow deleted your work too.

Thanks for giving the suggestions. I am checking the previous result in the source tree and it looks fine. I think I did not branch out from another branch, since I always create a new branch from master only.

hingen commented 1 year ago

Does it perhaps occur when you're doing a git merge?

For example, your teammate updated the master branch so you merge the updated master branch into your feature-branch. However, your teammate made some changes which overwrites your changes. If your feature-branch is very far behind on commits from the master branch, sometimes, git doesn't detect such changes as merge conflicts.

QQH0828 commented 1 year ago

Does it perhaps occur when you're doing a git merge?

For example, your teammate updated the master branch so you merge the updated master branch into your feature-branch. However, your teammate made some changes which overwrites your changes. If your feature-branch is very far behind on commits from the master branch, sometimes, git doesn't detect such changes as merge conflicts.

I have this issue even my teammates do not touch the master st all.

damithc commented 1 year ago

@QQH0828 Seems very specific to you Could be either you are doing something incorrectly or something wrong with your git/Sourcetree setup. But hard to decide without more details. Perhaps take screenshots are relevant points, or switch to CLI and share all the git commands you typed in your terminal so that others can see what exact operations you did.