In general, I need to switch files from Vetka1 to Vetku2 that are not used by Vetku2 and create those that are used by it.
In general, this is what happens. Let's start with the terminology to understand each other exactly.
A branch is just a lightweight commit pointer. It is implemented simply as a file, and the commit number (SHA-1) is in the file. Switching to another branch you actually switch to another commit.
Files and folders are not used by a branch or commit. It is more correct to say that the file (or a specific state of the file) belongs to a commit or is stored in a commit.
Commit inside contains the structure of files and folders that were saved in it, including the contents of files. At its core, this is such a "picture" of the working area of ββyour project.
When switching to another commit, all files and folders are rebuilt to the state that was saved in that commit. Let's imagine that we have two branches: master
and feature
and consider different situations. Here letters are different commits.
D feature / A--B--C/--E master*
We are in master and switch to feature:
git checkout feature
Suppose we have some file. Denote its content in commits C, D, E, in the project workspace (working tree, wt
) and the result of checkout
'a (or his attempts).
x
- file deleted1
, 2
, 3
- various content options
| C | E | D | wt | Π Π΅Π·ΡΠ»ΡΡΠ°Ρ --------------------------------------------------------------------- | 1 | 1 | 1 | 1 | 1, Π±Π΅Π· ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠΉ | 1 | 1 | 1 | 2 | 2, Π½Π΅ΡΠΎΡ
ΡΠ°Π½ΡΠ½Π½ΠΎΠ΅ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ ΠΎΡΡΠ°Π½Π΅ΡΡΡ | 1 | 1 | 3 | 1 | 3, ΡΠ΅ΡΡΡΡ Π½Π΅ΡΠ΅Π³ΠΎ, ΡΠΎΠ΄Π΅ΡΠΆΠΈΠΌΠΎΠ΅ ΠΏΡΠΎΡΡΠΎ ΠΌΠ΅Π½ΡΠ΅ΡΡΡ | 1 | 2 | 1 | 2 | 1, Π°Π½Π°Π»ΠΎΠ³ΠΈΡΠ½ΠΎ | 1 | 2 | 3 | 2 | 3, Π°Π½Π°Π»ΠΎΠ³ΠΈΡΠ½ΠΎ. # ΠΈΡΠΎΠ³: Π΅ΡΠ»ΠΈ ΠΏΠΎΡΠ»Π΅Π΄Π½Π΅Π΅ ΡΠΎΡΡΠΎΡΠ½ΠΈΠ΅ ΡΠ°ΠΉΠ»Π° Π·Π°ΠΊΠΎΠΌΠΌΠΈΡΠ΅Π½ΠΎ (E == wt), # ΠΊΠΎΠ½ΡΠ»ΠΈΠΊΡΠΎΠ² Π½ΠΈΠΊΠΎΠ³Π΄Π° Π½Π΅ Π±ΡΠ΄Π΅Ρ | 1 | 1 | 2 | 3 | Fail, Π±ΡΠ΄Π΅Ρ ΠΏΠΎΡΠ΅ΡΡ Π½Π΅ΡΠΎΡ
ΡΠ°Π½ΡΠ½Π½ΡΡ
ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠΉ | 1 | 2 | 2 | 3 | 3, git ΡΠ°ΡΠΏΠΎΠ·Π½Π°ΡΡ, ΡΡΠΎ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΡ Π² ΠΊΠΎΠΌΠΌΠΈΡΠ°Ρ
ΠΎΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²Ρ. | 1 | 2 | 3 | 3 | Fail. Π’Π΅ΠΊΡΡΠ΅Π΅ ΡΠΎΡΡΠΎΡΠ½ΠΈΠ΅ ΡΠ°ΠΉΠ»Π° ΡΠ°Π²Π½ΠΎ ΡΠΎΡ
ΡΠ°Π½ΡΠ½Π½ΠΎΠΌΡ Π² D, # Π½ΠΎ Ρ ΡΠΎΡΠΊΠΈ Π·ΡΠ΅Π½ΠΈΡ ΡΠ΅ΠΊΡΡΠ΅Π³ΠΎ ΠΊΠΎΠΌΠΌΠΈΡΠ° ΡΡΠΎ ΠΏΠΎΡΠ΅ΡΡ Π½Π΅ΡΠΎΡ
ΡΠ°Π½ΡΠ½Π½ΡΡ
ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠΉ. | 1 | 2 | 1 | 3 | Fail. ΠΠ°ΠΆΠ΅ Π΅ΡΠ»ΠΈ ΡΠ°ΠΉΠ» ΠΌΠ΅Π½ΡΠ»ΡΡ ΡΠΎΠ»ΡΠΊΠΎ Π² ΠΎΠ΄Π½ΠΎΠΌ ΠΊΠΎΠΌΠΌΠΈΡΠ΅, # Π½Π΅Π»ΡΠ·Ρ ΠΏΡΠΈΠΌΠ΅Π½ΠΈΡΡ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ "2" -> "3" ΠΊ ΡΠΎΠ΄Π΅ΡΠΆΠΈΠΌΠΎΠΌΡ "1" # ΡΠ΅ΠΏΠ΅ΡΡ ΠΏΠΎΡΠ΄Π°Π»ΡΠ΅ΠΌ. | C | E | D | wt | Π Π΅Π·ΡΠ»ΡΡΠ°Ρ --------------------------------------------------------------------- | 1 | x | 1 | x | 1. Π€Π°ΠΉΠ» Π²ΠΎΡΡΡΠ°Π½ΠΎΠ²Π»Π΅Π½, ΠΊΠ°ΠΊ ΡΠ°Π· ΡΠΎ ΡΡΠΎ Π²Π°ΠΌ Π½ΡΠΆΠ½ΠΎ. | 1 | 1 | x | 1 | x. Π ΡΠΎΠΉ Π²Π΅ΡΠΊΠ΅ ΡΠ°ΠΉΠ» ΡΠ΄Π°Π»ΡΠ½. | 1 | 1 | x | 2 | Fail, ΠΏΠΎΡΠ΅ΡΡ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠΉ. | 1 | 1 | 2 | x | Fail, ΡΠ΄Π°Π»Π΅Π½ΠΈΠ΅ - ΡΡΠΎ ΡΠΎΠΆΠ΅ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠ΅. | 1 | 1 | 1 | x | x, ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ Π΅ΡΡΡ, Π½ΠΎ ΠΊΠΎΠ½ΡΠ»ΠΈΠΊΡΠ° Π½Π΅Ρ. # Π€Π°ΠΉΠ» Π½Π΅Π·Π°Π²ΠΈΡΠΈΠΌΠΎ ΠΏΠΎΡΠ²ΠΈΠ»ΡΡ Π² ΡΠ°Π·Π½ΡΡ
Π²Π΅ΡΠΊΠ°Ρ
| x | 1 | 1 | 1 | 1, Π²ΡΡ Π½ΠΎΡΠΌΠ°Π»ΡΠ½ΠΎ | x | 1 | 2 | 1 | 2, Π΄Π°ΠΆΠ΅ Π΅ΡΠ»ΠΈ ΡΠΎΠ΄Π΅ΡΠΆΠΈΠΌΠΎΠ΅ ΡΠ°Π·Π½ΠΎΠ΅ | x | 1 | 2 | 2 | Fail, ΡΠ½ΠΎΠ²Π° ΠΏΠΎΡΠ΅ΡΡ, Ρ
ΠΎΡΡ ΡΠΎΠ΄Π΅ΡΠΆΠΈΠΌΠΎΠ΅ ΠΈ ΡΠΎΠ²ΠΏΠ°Π΄Π°Π΅Ρ.
Total, the result of the checkout
for each file can be described with the following pseudocode:
if (E == wt) { // ΠΡΠ»ΠΈ Π½Π΅Ρ Π½Π΅ΡΠΎΡ
ΡΠ°Π½ΡΠ½Π½ΡΡ
ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠΉ, Π±Π΅ΡΡΠΌ ΡΠΎΠ΄Π΅ΡΠΆΠΈΠΌΠΎΠ΅ ΠΈΠ· D return D } else if (E == D) { // ΠΡΠ»ΠΈ ΡΠΎΠ΄Π΅ΡΠΆΠΈΠΌΠΎΠ΅ Π½Π΅ ΠΌΠ΅Π½ΡΠ»ΠΎΡΡ (ΠΈΠ»ΠΈ ΠΌΠ΅Π½ΡΠ»ΠΎΡΡ ΠΎΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²ΠΎ), // Π’ΠΎ ΠΌΠΎΠΆΠ½ΠΎ ΠΎΡΡΠ°Π²ΠΈΡΡ ΡΠ΅ΠΊΡΡΠ΅Π΅ ΡΠΎΠ΄Π΅ΡΠΆΠΈΠΌΠΎΠ΅ ΡΠ°ΠΉΠ»Π° return wt } else { // ΠΠ½Π°ΡΠ΅ Π²Π΅ΡΠΎΡΡΠ½Π° ΠΏΠΎΡΠ΅ΡΡ Π΄Π°Π½Π½ΡΡ
fail() }
What can be done with unsaved changes:
- Check in
- Fold in pocket .
- Cancel using
git reset --hard -- filename
- in one filegit reset --hard
- undo all changes to versioned (tracked) filesgit clean -f
- generally clean the workspace, including deleting unversioned files. C -fx
will also remove ignored files, with -fd
take directories, not just files. Option -fdx
- napalm burning of everything that is not nailed.
Π° ΠΈΠ½Π°ΡΠ΅ Π·Π°ΡΠ΅ΠΌ ΡΠΎΠ·Π΄Π°Π²Π°ΡΡ gui-ΠΊΠ»ΠΈΠ΅Π½Ρ, ΠΊΠΎΡΠΎΡΡΠΉ Π½Π΅ ΠΌΠΎΠΆΠ΅Ρ ΡΠΎΠ³ΠΎ, ΡΡΠΎ ΠΌΠΎΠΆΠ΅Ρ ΠΊΠΎΠ½ΡΠΎΠ»Ρ
do - have not heard of a single client who can do anything that the console can. Still, in the console you are writing a program, even if one-line. But the majority of users do everything and do not need it. - Nick Volynkin β¦