You can, of course, with an explanation via the command line, but preferably through Git GUI (otherwise, why create a gui-client that cannot do what the console can do).

The bottom line is that different branches have a different number of files. And some of the files are used manually. 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. Is it possible?

Yes, I could ask the creators of the program about this, but here there is a chance for a quicker response, and, as I said, the solution via the console will also suit me.

  • 3
    What does "part of the file use manually" mean? - free_ze
  • 2
    Π° ΠΈΠ½Π°Ρ‡Π΅ Π·Π°Ρ‡Π΅ΠΌ ΡΠΎΠ·Π΄Π°Π²Π°Ρ‚ΡŒ 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 ♦

3 answers 3

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 deleted
  • 1 , 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:

  1. Check in
  2. Fold in pocket .
  3. Cancel using
    • git reset --hard -- filename - in one file
    • git reset --hard - undo all changes to versioned (tracked) files
    • git 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.
  • Thank you for your clarification, I will consider for the future. In my case, it was enough to switch to SourceTree, since he can do what he needs - user64675
  • @ user64675 please! It was interesting to sort through all possible cases. ) - Nick Volynkin ♦
  • @ user64675 looks like it’s still a long way off. ) - Nick Volynkin ♦

With git checkout %branch_name% status of the monitored files in the repository changes to the state of the extreme commit of this branch (i.e., the extra files will disappear, and the necessary files will be added). Modified and new (not fixed) files remain hanging.

You can also run git clean -dfx to clear the repository from untracked folders and files.

  • five
    git clean -dfx neat, it will also delete ignored files. It is not always good. - Nick Volynkin ♦
  • @NickVolynkin is true, nobody canceled the reading of the docks) - free_ze
  • Good illustration: pp.vk.me/c637328/v637328370/8e45/1-qBghDOJYw.jpg - Nick Volynkin ♦
  • @NickVolynkin Come on you, in the hands of an idiot and a hammer - a formidable weapon) - free_ze
  • one
    Described a couple of less destructive options: ru.stackoverflow.com/a/564056/181472 - Nick Volynkin ♦

if the files 'manually' are not registered and do not lie in the index in branch1, then in order to save them you need to put them on the shelf on demand by the command

git stash save --include-untracked "имя полки"

After that, switch to branch2. To view all the sticks, you need to use

 git stash list 

To extract the files you need to run

git stash apply "stash@{0}"

Need to use the desired index

The transition from branch2 is similar