Introduction class to Git version contoller
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.1 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. # Readme #
  2. This a repository example to practice the Git basic commands.
  3. # First commit #
  4. The first commit is the creation of the `file-a.md` file and some lines of code.
  5. Then the repository will be enable by
  6. ``` shell
  7. $ git init
  8. ```
  9. after that our first file has been created and will be filled with the next lines of code using the `echo` command or `Vim` editor:
  10. ``` shell
  11. vi file-a.md
  12. ```
  13. its contents is:
  14. ``` shell
  15. Line 1
  16. Line 2
  17. Line 3
  18. ```
  19. to quit `Vim` editor use `:wq!` in command mode (pressing first the ESC key)
  20. Then, we have to add the file we want to track by `git add <file(s)>` command:
  21. ``` shell
  22. $ git add file-a.md
  23. ```
  24. To finalize the process, we have to use the `git commit` command:
  25. ``` shell
  26. $ git commit -m "first commit"
  27. [master (root-commit) b441ef4] first commit
  28. 1 file changed, 3 insertions(+)
  29. create mode 100644 file-a.md
  30. ```
  31. the output from shell should be similar to code section above. Otherwise, you must provide your credentials as a new Git[^1] user with
  32. ``` shell
  33. $ git config --global user.name "Mona Lisa"
  34. $ git config --global user.email "my_email@domain.com"
  35. ```
  36. # Second commit #
  37. After the first commit, we can make some modifications to =file-a.md= file:
  38. ``` shell
  39. Line 0
  40. Line 1
  41. Line 2
  42. ```
  43. then, following the same procedure create and stage your second commit:
  44. ``` shell
  45. $ git status
  46. On branch master
  47. Changes not staged for commit:
  48. (use "git add <file>..." to update what will be committed)
  49. (use "git restore <file>..." to discard changes in working directory)
  50. modified: file-a.md
  51. $ git add file-a.md
  52. $ git commit -m "second commit"
  53. [master 5fdc115] second commit
  54. 1 file changed, 1 insertion(+), 1 deletion(-)
  55. ```
  56. # Difftool #
  57. To compare to commits, in this case our only commits, we will use the =difftool= command
  58. ``` shell
  59. $ git difftool b441ef4
  60. ```
  61. here the number =b441ef4= is the commit code number.
  62. A more simple way to observe what modifications on the repository is by using =git show= command
  63. ``` shell
  64. $ git show
  65. ```
  66. You can observe the log by using:
  67. ``` shell
  68. $ git log --graph --pretty
  69. ```
  70. [^1]: Don't forget to run Git Bash or powerShell as Admin user on Windows OS