Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

git-states 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. scriptloc=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
  4. r() {
  5. cmd=$*
  6. echo "\$ $cmd"
  7. eval $cmd
  8. echo "------------"
  9. }
  10. tmpdir=$(mktemp -d)
  11. pushd ${tmpdir}
  12. # delete temporary directory on script exit
  13. cleanup() {
  14. rm -rf "${tmpdir}"
  15. }
  16. trap cleanup EXIT
  17. clear
  18. # Initialise repository
  19. r git init
  20. git config --local user.name "Achilleas Koutsou"
  21. git config --local user.email "ak@example.com"
  22. r git status
  23. echo ":: Status: Initialised; no commits; no files"
  24. read
  25. clear
  26. # ADD README
  27. echo "
  28. # Demo repository
  29. Repository for demonstrating git workflow and file state cycle
  30. " > README.md
  31. r git status
  32. echo ":: Status: No commits; one *untracked* file"
  33. read
  34. clear
  35. r git add README.md
  36. r git status
  37. echo ":: Status: No commits; one *tracked* file, *staged*"
  38. read
  39. clear
  40. # Commit
  41. r git commit -m '"Initial commit: Add README"'
  42. r git status
  43. echo ":: Status: Clean! One unmodified file (doesn't show up in status)"
  44. read
  45. clear
  46. # EDIT README
  47. echo "
  48. © AK 2019
  49. " >> README.md
  50. r git status
  51. echo ":: Status: README is modified"
  52. read
  53. clear
  54. # STAGE README
  55. git add -u # -u stages all *tracked* *modified* files (stands for update); does not add untracked files
  56. r git status
  57. echo ":: Status: README is staged"
  58. read
  59. clear
  60. # Create python file in source directory
  61. mkdir src
  62. echo "import sys
  63. def main():
  64. args = sys.argv
  65. print(f'Script name {args[0]}')
  66. print('Arguments received')
  67. for idx, arg in enumerate(sys.agv):
  68. print(f'{idx}: {arg}')
  69. if __name__ == "__main__":
  70. main()
  71. " > src/script.py
  72. r git status
  73. echo ":: Status: A new file appears, so it's untracked"
  74. echo ":: Since the entire 'src' directory is untracked, we only see the name of the directory"
  75. read
  76. clear
  77. # ADD the script
  78. git add src
  79. r git status
  80. echo ":: Status: Both files are staged"
  81. read
  82. clear
  83. # Commit staged files
  84. r git commit -m '"Add script.py and copyright year"'
  85. r git status
  86. echo ":: Status: Commit done; all is clean"
  87. read
  88. clear
  89. # Moving backwards through states
  90. echo "Just some notes, do not commit" > notes.txt
  91. git add notes.txt
  92. r git status
  93. echo ":: Status: New staged file; added accidentally"
  94. read
  95. clear
  96. # Unstage it
  97. r git reset HEAD notes.txt
  98. r git status
  99. echo ":: Status: unstaged (back to untracked) using 'git reset HEAD'"
  100. read
  101. clear
  102. # Let's try that with one of our tracked files
  103. echo "Another note" > src/script.py
  104. r git status
  105. r cat src/script.py
  106. echo ":: OH NO! We wiped our script"
  107. read
  108. r git checkout -- src/script.py
  109. r git status
  110. r cat src/script.py
  111. echo ":: SAVED"
  112. read
  113. clear
  114. # Let's do that again
  115. echo "Note three" > src/script.py
  116. r git add src
  117. r git commit -m '"Commit: some notes"'
  118. r git status
  119. echo ":: All clean except untracked notes"
  120. read
  121. r cat src/script.py
  122. echo ":: Oops, we overwrote our script (again) and committed it!"
  123. read
  124. clear
  125. r git log
  126. echo ":: git log: repository history"
  127. read
  128. clear
  129. # Let's find out when this happened
  130. r git log -- src/script.py
  131. echo ":: History of specific file"
  132. read
  133. clear
  134. # Can also show the actual changes
  135. r git log -p -- src/script.py
  136. echo ":: History with differences (-p: patch)"
  137. read
  138. clear
  139. # Previous commit has our file in good condition
  140. r git checkout HEAD~1 -- src/script.py
  141. r cat src/script.py
  142. r git status
  143. echo ":: Status: checked out old version of file; the checkout also staged the change"
  144. # Commit the correction
  145. r git commit -m '"Get back good script.py"'
  146. r git status
  147. read
  148. clear
  149. r git log
  150. read