Skip to content
Extraits de code Groupes Projets
Valider ca7f0b97 rédigé par Pierre-Yves Barriat's avatar Pierre-Yves Barriat
Parcourir les fichiers

Upgrade git 2025

parent 44d7fddd
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 261 ajouts et 9 suppressions
......@@ -40,7 +40,7 @@ git config --global push.default simple
Clone the Git_Training repository :
```bash
git clone https://forge.uclouvain.be/barriat/learning-git
git clone https://forge.uclouvain.be/elic/learning.git
```
### Windows or Mac
......@@ -50,7 +50,7 @@ git clone https://forge.uclouvain.be/barriat/learning-git
Clone the Git_Training repository:
```bash
https://forge.uclouvain.be/barriat/learning-git
https://forge.uclouvain.be/elic/learning.git
```
For instance, paste the URL into **gitforwindows** and it will clone the repo locally on your computer:
......
You have accidentaly put `first.txt` in the **staging area**
While you actually want to only commit `second.txt`.
You need to, from the current state, only commit `second.txt`:
- remove the file `first.txt` (Use `git status` to get the appropriate command)
- add `second.txt`
- commit
#!/bin/bash
rm -f first.txt second.txt 2> /dev/null
echo "un" > first.txt
echo "deux" > second.txt
git add first.txt
@echo off
SET SOME_VAR=.\first.txt
DEL /S "%SOME_VAR%" || echo "file not found"
SET SOME_VAR=.\second.txt
DEL /S "%SOME_VAR%" || echo "file not found"
CALL :_ex
EXIT /B %ERRORLEVEL%
:_ex
echo "2 files have been created !"
echo un> first.txt
echo deux> second.txt
dir *.txt
git add first.txt
EXIT /B 0
You just wrote a cpp program that reads it config from a file named `conf.ini`
As you don't want to bother adding all files manualy, you have decided to use `.gitignore`
You need to create a `.gitignore` file that will:
- ignore all files that end with suffix `.swp` (backup files)
- ignore every files in the `out` directory except `conf.ini`
In other words, once the `.gitignore` file written, the command `git add .` should only stage:
- .gitignore
- main.cpp
- out/conf.ini
#!/bin/bash
rm -rf out main.cp* 2> /dev/null
touch main.cpp
touch main.cpp.swp
mkdir out
touch out/main.o
touch out/a.out
touch out/conf.ini
@echo off
SET SOME_VAR="main.cpp"
DEL /S "%SOME_VAR%" || echo "file not found"
SET SOME_VAR="main.cpp.swp"
DEL /S "%SOME_VAR%" || echo "file not found"
SET SOME_VAR=out
RD /S /Q "%SOME_VAR%" || echo "file not found"
CALL :_ex
EXIT /B %ERRORLEVEL%
:_ex
echo >"main.cpp"
echo >"main.cpp.swp"
mkdir "out"
echo >"out\main.o"
echo >"out\a.out"
echo >"out\conf.ini"
EXIT /B 0
You just realized that you have commited a backup file: `main.cpp.swp`
Backup files should not be commited, let's correct that mistake :
- delete the file with `rm`
- add all changes, including deleted files with `git add -A`
- write a gitignore that will correct your mistake
- add it
- commit
#!/bin/bash
rm -f main.cp* 2> /dev/null
touch main.cpp
touch main.cpp.swp
git add .
git commit -m "first commit"
@echo off
SET SOME_VAR="main.cpp"
DEL /S "%SOME_VAR%" || echo "file not found"
SET SOME_VAR="main.cpp.swp"
DEL /S "%SOME_VAR%" || echo "file not found"
CALL :_ex
EXIT /B %ERRORLEVEL%
:_ex
echo >"main.cpp"
echo >"main.cpp.swp"
git add .
git commit -m "first commit"
EXIT /B 0
You just ran a `git fetch` and realize someone has modified the exact file at the exact line that you just worked on.
You want the current state of your working directory to be saved.
Conflict seems inevitable.
- create a commit with the new version of first.txt
- use `git pull` to merge origin/master into your master
- resolve the conflict in first.txt
- commit
one
two
#!/bin/bash
rm -f first.txt 2> /dev/null
touch first.txt
git add .
git commit -m "First commit"
echo "one" >> first.txt
git commit -am "Added one"
echo "two" >> first.txt
git commit -am "Added two"
git push -u origin master
git reset --hard HEAD~1
echo "three" >> first.txt
@echo off
SET SOME_VAR="first.txt"
DEL /S "%SOME_VAR%" || echo "file not found"
CALL :_ex
EXIT /B %ERRORLEVEL%
:_ex
echo >first.txt
git add .
git commit -m "First commit"
echo "one">>first.txt
git commit -am "Added one"
echo "two">>first.txt
git commit -am "Added two"
git push -u origin master
git reset --hard HEAD~1
echo "three">>first.txt
EXIT /B 0
## PART 1
You have worked hard and the result is beautiful.
But somehow there's a bug.
It's late, your partner wants you to go home.
Hell, maybe a good night sleep (or a good night something else) will help you find that stupid bug.
So you want to go home, but you don't want to leave the work unsaved, that would be unprofessional. And you're a pro.
So, as the code cannot be merged into master yet, you decide to create a branch.
- create and checkout a new branch named "file-second"
- commit the current state
- push it (remember, the branch does not exists yet on origin)
## PART 2
Your mind is clear and ready to tackle that nasty bug.
As you march to your desk like the conquerant you are, your boss stops you.
There's an urgent fix that needs to go out in prod just right now.
- checkout the branch master
- pull it to get the last version
- add a "three" to the file first.txt
- commit and push the changes to that new file
## PART 3
Now is the time to tackle the problem, let's get back to your work.
- checkout the branch file-second
## PART 4
Of couuuuurse !
You found it, the 'E' is missing between 'D' and 'F'
After fixing the bug, the awesomeness can be mnerged into master.
- modify the file so that it's beauty is complete
- commit the difference
- push it
- merge it into master
- push master
- brag
## PART 5
You are a good citizen (or at least in this story we assume you are).
You are not working anymore on the branch file-second
- delete the branch file-second both localy and in origin
#!/bin/bash
rm -f first.txt second.txt 2> /dev/null
touch first.txt
git add .
git commit -m "First commit"
echo "one" >> first.txt
git commit -am "Added one"
echo "two" >> first.txt
git commit -am "Added two"
git push -u origin master
git reset --hard HEAD~1
echo "A B C D F G" >> second.txt
@echo off
SET SOME_VAR="first.txt"
DEL /S "%SOME_VAR%" || echo "file not found"
SET SOME_VAR="second.txt"
DEL /S "%SOME_VAR%" || echo "file not found"
CALL :_ex
EXIT /B %ERRORLEVEL%
:_ex
echo >"first.txt"
git add .
git commit -m "First commit"
echo "one">>first.txt
git commit -am "Added one"
echo "two">>first.txt
git commit -am "Added two"
git push -u origin master
git reset --hard HEAD~1
echo "A B C D F G">second.txt
EXIT /B 0
......@@ -19,10 +19,10 @@ It is very simple, only consists in a couple of files written in bash and you wi
In this tutorial you will learn how to make commits in the Git project, to create several branches, to push things to Gogs, and to follow a standard procedure to develop collaboratively. Afterwards, you should apply the same methods to any other collaborative development inside the ELIC department. The objectives will be achieved gradually following these topics:
1. [Set up your working environment](https://gogs.elic.ucl.ac.be/TECLIM/Git_Training/src/master/project/linux/working_environment)
2. [Prepare issues on Gogs](https://gogs.elic.ucl.ac.be/TECLIM/Git_Training/src/master/project/linux/gogs_issues)
3. [Prepare branches](https://gogs.elic.ucl.ac.be/TECLIM/Git_Training/src/master/project/linux/branches)
4. [Add new functions](https://gogs.elic.ucl.ac.be/TECLIM/Git_Training/src/master/project/linux/functions)
5. [Create pull request](https://gogs.elic.ucl.ac.be/TECLIM/Git_Training/src/master/project/linux/pull_request)
6. [Review and test others' branches](https://gogs.elic.ucl.ac.be/TECLIM/Git_Training/src/master/project/linux/review)
7. [Pull master changes](https://gogs.elic.ucl.ac.be/TECLIM/Git_Training/src/master/project/linux/pull_master)
1. [Set up your working environment](https://forge.uclouvain.be/elic/learning/-/tree/main/learning-git/project/linux/working_environment)
2. [Prepare issues on Gogs](https://forge.uclouvain.be/elic/learning/-/tree/main/learning-git/project/linux/gogs_issues)
3. [Prepare branches](https://forge.uclouvain.be/elic/learning/-/tree/main/learning-git/project/linux/branches)
4. [Add new functions](https://forge.uclouvain.be/elic/learning/-/tree/main/learning-git/project/linux/functions)
5. [Create pull request](https://forge.uclouvain.be/elic/learning/-/tree/main/learning-git/project/linux/pull_request)
6. [Review and test others' branches](https://forge.uclouvain.be/elic/learning/-/tree/main/learning-git/project/linux/review)
7. [Pull master changes](https://forge.uclouvain.be/elic/learning/-/tree/main/learning-git/project/linux/pull_master)
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter