Is it good to store files often when using Mercurial or Git?

It seems that we recommend often fixing intermediate changes to the code that we wrote ... for example, on hginit.com, when using Mercurial or Git.

However, let's say if we are working on a project and we often commit files. Now, for one reason or another, the manager wants part of the function to exit, so we need to push, but I heard that it is impossible to push individual files or a folder on Mercurial or Git ... either everything that happens is pushed, or nothing will push. Therefore, we either have to return all the files that we don’t want to click, or we just never have to perform actions until we click - right after the commit, we click?

+3
source share
4 answers

The best way to handle this (whether you use Mercurial, Git, or any other version control system) is to make sure your work is done on branches that correspond to these “parts of the function”. If there is even a small chance that some part of the work should be released independently of another work, it should have its own branch from the very beginning.

This gives you the ability to push only the “part of the feature” and is much better suited when the “part of the function” and some other “parts of the function” contain changes to the same file.

Mercurial Git , , ( ) .

. , , . , 100 ( ), 1 . , , , , push . Mercurial :

$ cd ~/project
$ hg clone http://server/project/trunk trunk-oops
$ cp trunk/shouldve-branched trunk-oops/shouldve-branched
$ cd trunk-oops; hg addrem; hg ci -m "We need to organize better!"; hg push
$ cd ../trunk; hg fetch ../trunk-oops
+11

.

. .

+4

. , / .

+3

, : .

, . : , , ( git). , , . , , .

:

One branch, few commits:

- A1 - B1 - C1 - B2 - A2 - B3 - C3 (master)

Many branches, many commits:

  M1 - M2 (master)
 /
o - A1 - A2 - A3 - A4 - A5 - A6 (topicA)
|\
| B1 - B2 - B3 - B4 - B5 - B6 - B7 (topicB)
\ 
 C1 - C2 - C3 - C4 - C5 (topicC)

, , , , ! A, A1, A3, A4 A6, , , topicA, , master, . topicA (A2 A5) .

  M1 - M2 ------------- X (master)
 /                     /
o - A1 - A3' - A4' - A6' - A2' - A5' (topicA)

(Commits A1 ',... git , .)

+1

Source: https://habr.com/ru/post/1749464/


All Articles