Resolving Unstaged Git Changes
Now that you've identified the unstaged changes in your Git repository, it's time to resolve them. LabEx provides several methods to handle these changes, depending on your specific needs.
Staging Unstaged Changes
To add the unstaged changes to the staging area, you can use the git add
command. This will move the changes from the working directory to the staging area, preparing them for the next commit.
$ git add README.md src/main.py
After running this command, the changes to README.md
and src/main.py
will be staged and ready for commit.
Discarding Unstaged Changes
If you don't want to keep the changes you've made, you can discard them using the git restore
command. This will revert the files in your working directory to their last committed state.
$ git restore README.md src/main.py
This will discard the changes you made to README.md
and src/main.py
, effectively resetting them to their previous state.
Partially Staging Changes
Sometimes, you may want to stage only a portion of the changes you've made. You can do this using the git add -p
command, which will walk you through the changes and allow you to selectively stage them.
$ git add -p
diff --git a/README.md b/README.md
index 45b983b..f42f863 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,2 @@
hi
+This is an updated README file.
Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]? y
By using these methods, you can effectively manage and resolve your unstaged Git changes, ensuring that your repository is in the desired state before committing your work.