Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+19 votes

For Lab 6, after doing part C I wanted to go back to part B and make some changes to the PasswordsUtils class but I forgot to switch to the main branch, so I changed the code on the analytics branch. So when I wanted to go back to the main branch and change the code there, I couldn't do it and it was saying that I need to commit or stash the changes first before I switch branches. Was it possible to remove all the changes on eclipse and not commit or stash ?

asked in CSC305 Fall 2022 by (1 point)

1 Answer

+9 votes

See: https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/remove-revert-discard-local-uncommitted-changes-Git-how-to

But actually, I think the newer git restore command is preferred over the git reset ... command in this situation.

To discard changes to a specific file, you can do:

 git restore filename

To discard changes to the current folder, use:

git restore .

You may still need to use git clean -fxd to remove any files that are not tracked by git. (Note: git clean can be risky, since deleting files that are not tracked by git means there is often no way to get those files back after they have been deleted. Maybe try git clean -fxdn first as a "dry run" to see what files will be deleted if you run it without the n option. )

answered by (508 points)
+4

Ok thank you, I have another question why do we need to remove untracked files if they aren't saved in git database?

...