416 liens privés
j'ai fait 3 git commits, mais je n'ai pas été poussé. Comment puis-je modifier l'ancienne (DD 6859af44) et (47175e84c) qui n'est pas la plus récente?
$git log
commit f4074f289b8a49250b15a4f25ca4b46017454781
Date: Tue Jan 10 10:57:27 2012 -0800
commit ddc6859af448b8fd2e86dd0437c47b6014380a7f
Date: Mon Jan 9 16:29:30 2012 -0800
commit 47175e84c2cb7e47520f7dde824718eae3624550
Date: Mon Jan 9 13:13:22 2012 -0800
git rebase -i HEAD^^^
Inscrivez maintenant ceux que vous voulez modifier avec edit ou e (remplacer pick ). Maintenant, enregistrez et sortez.
faites vos modifications, puis
git add -A
git commit --amend --no-edit
git rebase --continue
si vous voulez ajouter une suppression supplémentaire supprimez les options de la commande commit. Si vous voulez ajuster le message, omettez simplement l'option --no-edit .
.gitignore will prevent untracked files from being added (without an add -f) to the set of files tracked by Git, however Git will continue to track any files that are already being tracked.
To stop tracking a file you need to remove it from the index. This can be achieved with this command.
git rm --cached <file>
If you want to remove a whole folder, you need to remove all files in it recursively.
git rm -r --cached <folder>
The removal of the file from the head revision will happen on the next commit.
WARNING: While this will not remove the physical file from your local, it will remove the files from other developers machines on next git pull.
Initialize
| gitflow | git |
|---|---|
git flow init |
git init |
git commit --allow-empty -m "Initial commit" |
|
git checkout -b develop master |
Connect to the remote repository
| gitflow | git |
|---|---|
| N/A | git remote add origin git@github.com:MYACCOUNT/MYREPO |
Features
Create a feature branch
| gitflow | git |
|---|---|
git flow feature start MYFEATURE |
git checkout -b feature/MYFEATURE develop |
Share a feature branch
| gitflow | git |
|---|---|
git flow feature publish MYFEATURE |
git checkout feature/MYFEATURE |
git push origin feature/MYFEATURE |
Get latest for a feature branch
| gitflow | git |
|---|---|
git flow feature pull origin MYFEATURE |
git checkout feature/MYFEATURE |
git pull --rebase origin feature/MYFEATURE |
Finalize a feature branch
| gitflow | git |
|---|---|
git flow feature finish MYFEATURE |
git checkout develop |
git merge --no-ff feature/MYFEATURE |
|
git branch -d feature/MYFEATURE |
Push the merged feature branch
| gitflow | git |
|---|---|
| N/A | git push origin develop |
git push origin :feature/MYFEATURE (if pushed) |
Releases
Create a release branch
| gitflow | git |
|---|---|
git flow release start 1.2.0 |
git checkout -b release/1.2.0 develop |
Share a release branch
| gitflow | git |
|---|---|
git flow release publish 1.2.0 |
git checkout release/1.2.0 |
git push origin release/1.2.0 |
Get latest for a release branch
| gitflow | git |
|---|---|
| N/A | git checkout release/1.2.0 |
git pull --rebase origin release/1.2.0 |
Finalize a release branch
| gitflow | git |
|---|---|
git flow release finish 1.2.0 |
git checkout master |
git merge --no-ff release/1.2.0 |
|
git tag -a 1.2.0 |
|
git checkout develop |
|
git merge --no-ff release/1.2.0 |
|
git branch -d release/1.2.0 |
Push the merged feature branch
| gitflow | git |
|---|---|
| N/A | git push origin master |
git push origin develop |
|
git push origin --tags |
|
git push origin :release/1.2.0 (if pushed) |
Hotfixes
Create a hotfix branch
| gitflow | git |
|---|---|
git flow hotfix start 1.2.1 [commit] |
git checkout -b hotfix/1.2.1 [commit] |
Finalize a hotfix branch
| gitflow | git |
|---|---|
git flow hotfix finish 1.2.1 |
git checkout master |
git merge --no-ff hotfix/1.2.1 |
|
git tag -a 1.2.1 |
|
git checkout develop |
|
git merge --no-ff hotfix/1.2.1 |
|
git branch -d hotfix/1.2.1 |
Push the merged hotfix branch
| gitflow | git |
|---|---|
| N/A | git push origin master |
git push origin develop |
|
git push origin --tags |
|
git push origin :hotfix/1.2.1 (if pushed) |
References
Désynchronisation
Les branches, locales ou distantes, se désynchronisent nécessairement :
modifications locales,
modifications distantes par un collaborateur,
branches expérimentales,
retour dans le passé…
Commandes fondamentales :
fetch : télécharge toutes les modifications distantes, sans toucher à l’historique local.
status : montre l’état de synchronisation.
merge : importe les commits d’une autre branche.
pull : équivalent de fetch, puis merge (avec branche tracée).
Modifications locales
Le répertoire a changé localement, l’origine n’a pas bougé.
git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
L’origine peut être mise à jour par un fast-forward.
git push
origin
e137e9b..master
HEAD
Utilser push pour mettre à jour le remote.
Local RepositoryCurrent Branch: master
a9120c2..32320ed..e137e9b..origin/mastermaster
HEAD
Modifications distantes
L’origine a changé, le répertoire local n’a pas bougé
git status
On branch master
Your branch is behind 'origin/master' by 2 commits,
and can be fast-forwarded.
(use "git pull" to update your local branch)
Le répertoire locale peut être mis à jour par un fast forward.
git pull
origin
a9120c2..32320ed..e137e9b..master
HEAD
Faire un fetch, puis un pull.
Local RepositoryCurrent Branch: master
e137e9b..masterorigin/master
HEAD
Historique divergent
Les deux branches ont subi des modifications concurrentes.
git status
On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Le fast-forward est impossible. Il est nécessaire de faire un merge.
Télécharger et faire un merge
git pull
Annuler si le merge n’est pas un fast-forward
git pull --ff-only
origin
a9120c2..32320ed..e137e9b..master
HEAD
Faire un fetch, puis un pull.
Local RepositoryCurrent Branch: master
93128ab..e137e9b..origin/mastermaster
HEAD
Les conflits, ça arrive
git pull
Auto-merging tutorials/tutorial4.md
CONFLICT (content): Merge conflict in tutorials/tutorial4.md
Automatic merge failed; fix conflicts and then commit the result.
git status
On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
You have unmerged paths.
(fix conflicts and run "git commit")
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: tutorials/tutorial4.md
no changes added to commit (use "git add" and/or "git commit -a")
Anatomie d’un conflit
Lorem ispsum
<<<<<<< HEAD
dolor sit amet
dolor sit amemus
a10ce40a3d3aedd7b4517249df5615b08087a044
quousque tandem
Modifications locales (HEAD),
Modifications distantes,
Contexte.
L’utilisateur qui réalise le merge doit choisir une résolution pour le conflit.
Une fois le conflit résolu : add, puis commit.
Outils pour l’aide à la résolution de conflits : KDiff3, DiffMerge, Meld, …
Récrire l’histoire
Important : On ne récrit jamais l’historique d’un répertoire partagé : origin n’oublie pas !
Cependant, on est libres de faire ce que l’on veut avec ses branches locales :
commit --amend : récrit les métadonnées d’un commit.
revert : crée un commit qui défait un commit précédent.
reset : revient à un ancien commit.
reset --hard : revient à un ancien commit, et modifie les fichiers.
rebase : rejoue une suite de commits à partir d’un autre point de l’histoire.
cherry-pick : rejoue un commit à partir de HEAD.
show et checkout permettent aussi d’examiner les fichiers tels qu’ils étaient à un moment dans l’historique.
Oublier des commits : reset
Revenir à un moment de l’histoire, les fichiers ne sont pas touchés
git reset SHA
checkout permet de reporter des fichiers individuels à l’état du commit.
Revenir à un moment de l’histoire, les fichiers sont reportés à l’état du commit
git reset --hard SHA
Attention : ceci détruit tous les changements non commités.
Essayez reset
Local RepositoryCurrent Branch: master
7d394ac..af90193..93128ab..e137e9b..masterHEAD
topic
Rejouer des commits : rebase
Rejouer les commits à partir du dernier commit commun
git rebase <branch>
Faire un fetch et rejouer les commits d’un seul coup
git pull --rebase
Alternative au merge classique. Adapté pour des petites modifications à pousser immédiatement.
origin
a9120c2..32320ed..e137e9b..master
HEAD
Essayez rebase
Local RepositoryCurrent Branch: master
7d394ac..af90193..93128ab..e137e9b..origin/mastermasterHEAD
topic
Récrire l’histoire distante
Récrire l’histoire de origin, c’est mal. Mais…
Remplacer l’historique distant avec l’historique local
git push -f
Effacer une branche distante
git push origin :<branche>
À n’utiliser que si vous savez vraiment ce que vous faites !