\begin{frame}[fragile] \frametitle{Sans modification d'historique} \begin{block}{} \enquote{ Dis, je me suis planté sur un commit, j'aimerais bien l'annuler \ldots C'est possible ? \\ Oui ! Utilises git revert ! } \end{block} \verb+git revert+ permet d'annuler un commit, en en créant un commit qui fait les modifications inverses. \begin{beamercolorbox}[rounded=true, shadow=true]{terminal} \begin{Verbatim} $ git revert HEAD \Pause [master 6e23b65] Revert "Troisième commit" 1 file changed, 1 deletion(-) \end{Verbatim} \end{beamercolorbox} \end{frame} \begin{frame}[fragile] \begin{beamercolorbox}[rounded=true, shadow=true]{terminal} \begin{Verbatim} $ git show HEAD \Pause \textcolor{yellow}{commit 6e23b65243628f81924f650466c86ef3a8e42ec5 (}{\bf\textcolor{cyan}{HEAD -> }\textcolor{green}{master}}\textcolor{yellow}{)} Author: huetremy Date: Fri Jan 11 14:20:59 2019 +0100 Revert "Troisième commit" This reverts commit a04da653083b6b0ba3eea2bce98d903acfd0a4d3. diff --git a/API.txt b/API.txt index a03f78c..5596950 100644 --- a/API.txt +++ b/API.txt \textcolor{cyan}{@@ -1,3 +1,2 @@} Je suis le premier fichier utilisé pour cette API sur git J'ajoute une ligne à mon fichier \textcolor{red}{-Encore une ligne en plus !} \Pause $ git diff HEAD\~{}2 \end{Verbatim} \end{beamercolorbox} \end{frame} \begin{frame}[fragile] \frametitle{Avec modification d'historique} \framesubtitle{Git reset} \begin{block}{À quoi ça sert ?} \begin{itemize} \item \verb+git reset+ permet de remettre le HEAD dans un état spécifique, et modifie l'arbre en conséquence (supprime tous les commits après) \item \verb+git reset --soft+ laisse le working directory dans l'état dans lequel il était \item \verb+git reset --hard+ remet le working directory dans l'état du commit sur lequel on reset. \end{itemize} \end{block} \begin{beamercolorbox}[rounded=true, shadow=true]{terminal} \begin{Verbatim} $ git reset --soft HEAD~1 \Pause $ cat API.txt \Pause Je suis le premier fichier utilisé pour cette API sur git J'ajoute une ligne à mon fichier \end{Verbatim} \end{beamercolorbox} \end{frame} \begin{frame}[fragile] \begin{beamercolorbox}[rounded=true, shadow=true]{terminal} \begin{Verbatim} $ git log --graph --decorate --all \Pause * \textcolor{yellow}{commit a04da653083b6b0ba3eea2bce98d903acfd0a4d3 (}{\bf\textcolor{cyan}{HEAD -> }\textcolor{green}{master}}\textcolor{yellow}{)} \textcolor{red}{|} Author: huetremy \textcolor{red}{|} Date: Fri Jan 11 10:16:10 2019 +0100 \textcolor{red}{|} \textcolor{red}{|} Troisième commit \textcolor{red}{|} * \textcolor{yellow}{commit 5b63bd1f9afe4685b60074030960e39bb5152e67} \textcolor{red}{|} Author: Thibaud Duhautbout \textcolor{red}{|} Date: Thu Jan 3 15:55:33 2019 +0100 \textcolor{red}{|} \textcolor{red}{|} Second commit \textcolor{red}{|} * \textcolor{yellow}{commit 712951dbb3ee0cc4d248582dc5408da3afdec853 (tag: mon_tag)} Author: Thibaud Duhautbout Date: Thu Jan 3 15:37:54 2019 +0100 Ajout du premier fichier \end{Verbatim} \end{beamercolorbox} On voit bien grâce qux deux commandes précédentes que le commit a été supprimé mais que les modifications ont été gardées\ldots Maintenant : \begin{beamercolorbox}[rounded=true, shadow=true]{terminal} \begin{Verbatim} $ git commit -am ''Commit de revert'' \Pause [master eae33f2] Commit de revert 1 file changed, 1 deletion(-) \end{Verbatim} \end{beamercolorbox} \end{frame} \begin{frame}[fragile] \begin{beamercolorbox}[rounded=true, shadow=true]{terminal} \begin{Verbatim} $ git reset --hard HEAD~1 \Pause HEAD est maintenant à a04da65 Troisième commit \Pause $ cat API.txt \Pause Je suis le premier fichier utilisé pour cette API sur git J'ajoute une ligne à mon fichier Encore une ligne en plus ! \Pause $ git log --graph --decorate --all \Pause * \textcolor{yellow}{commit a04da653083b6b0ba3eea2bce98d903acfd0a4d3 (}{\bf\textcolor{cyan}{HEAD -> }\textcolor{green}{master}}\textcolor{yellow}{)} \textcolor{red}{|} Author: huetremy \textcolor{red}{|} Date: Fri Jan 11 10:16:10 2019 +0100 \textcolor{red}{|} \textcolor{red}{|} Troisième commit \textcolor{red}{|} * \textcolor{yellow}{commit 5b63bd1f9afe4685b60074030960e39bb5152e67} \textcolor{red}{|} Author: Thibaud Duhautbout \textcolor{red}{|} Date: Thu Jan 3 15:55:33 2019 +0100 \textcolor{red}{|} \textcolor{red}{|} Second commit \textcolor{red}{|} * \textcolor{yellow}{commit 712951dbb3ee0cc4d248582dc5408da3afdec853 (tag: mon_tag)} Author: Thibaud Duhautbout Date: Thu Jan 3 15:37:54 2019 +0100 Ajout du premier fichier \end{Verbatim} \end{beamercolorbox} Le commit a bien été effacé, mais cette fois les modifications n'ont pas été gardées \end{frame} \begin{frame}[fragile] \frametitle{Avec modification d'historique} \framesubtitle{Git commit --amend} \begin{block}{} \enquote{ Dis, j'aimerais faire une toute petite modification sur un commit, c'est possible ? \\ -- Oui ! Utilises git commit \--\--ammend } \end{block} \verb+git commit --ammend+ permet de modifier un commit (tant son message que son contenu, son auteur \ldots) \begin{beamercolorbox}[rounded=true, shadow=true]{terminal} \begin{Verbatim} $ echo "Je suis l'apiinit" >> API.txt && git commit -am "Commit supplémentaire" \Pause $ sed -i "s|apiinit|Api/casoft init|" API.txt \Pause $ git commit -a --amend \Pause [master 168efba] Commit supplémentaire Date: Fri Jan 11 14:53:09 2019 +0100 1 file changed, 1 insertion(+) \end{Verbatim} \end{beamercolorbox} \end{frame} \begin{frame}[fragile] \begin{beamercolorbox}[rounded=true, shadow=true]{terminal} \begin{Verbatim} $ git log --graph --decorate \Pause * \textcolor{yellow}{commit 168efba77dcfd59ba4346fe4a34427b71db75da7 (}{\bf\textcolor{cyan}{HEAD -> }\textcolor{green}{master}}\textcolor{yellow}{)} \textcolor{red}{|} Author: huetremy \textcolor{red}{|} Date: Fri Jan 11 14:53:09 2019 +0100 \textcolor{red}{|} \textcolor{red}{|} Commit supplémentaire \textcolor{red}{|} * \textcolor{yellow}{commit a04da653083b6b0ba3eea2bce98d903acfd0a4d3} \textcolor{red}{|} Author: huetremy \textcolor{red}{|} Date: Fri Jan 11 10:16:10 2019 +0100 \textcolor{red}{|} \textcolor{red}{|} Troisième commit \textcolor{red}{|} [\ldots] \Pause $ git show HEAD \Pause \textcolor{yellow}{commit 168efba77dcfd59ba4346fe4a34427b71db75da7 (}{\bf\textcolor{cyan}{HEAD -> }\textcolor{green}{master}}\textcolor{yellow}{)} Author: huetremy Date: Fri Jan 11 14:53:09 2019 +0100 Commit supplémentaire {\bf{}diff --git a/API.txt b/API.txt} {\bf{}index a03f78c..4af702a 100644} {\bf{}--- a/API.txt} {\bf{}+++ b/API.txt} \textcolor{cyan}{@@ -1,3 +1,4 @@} Je suis le premier fichier utilisé pour cette API sur git J'ajoute une ligne à mon fichier Encore une ligne en plus ! \textcolor{myGreen}{+Je suis l'Api/casoft init} \end{Verbatim} \end{beamercolorbox} \end{frame}