With Git, how can I make some changes to the working copy in another branch?

I work in a branch and get a working copy with a really dirty one. When viewing the changes in commit, I wanted some oneliner fixes to be branch bound master.

In this case, the use git stashdoes not really help, because there are many other changes in my working copy that will not merge with the master yet.

Is there a better way to fix this? (e.g. committing and moving a parent?)

+3
source share
6 answers

Based on previous suggestions, this is the solution I came across:

1

:

git add --patch <files>      # record every change to move to master
git commit

git stash
git checkout master
git cherry-pick <commitid>

, .

git checkout <branch>
git rebase master

:

git rebase --skip

, . git merge - .

2

, :

git add --patch <files>      # record every change to move to master

:

git stash --keep-index       # clear the working copy only
git checkout master -m       # merge the index.
git commit

, :

git checkout <branchname>
git rebase master            # move to branch start to the tip of master.
git stash apply              # restore working copy, auto merges the changes

3,

( SVN ), :

mkdir ../newrepos
cd ../newrepos
git init
git remote add origin /path/to/your/repository
git fetch master:remotes/origin/master  # fetch remote master to local remotes/origin/master
git checkout -t origin/master           # make new "master" branch, link to remote, checkout.

git commit
git push origin master                  # inject the change in the original repository.

, git clone .


git diff > to-master.patch git apply to-master.patch. reset , , .

, . , checkout -m.

+1

git add -i . , .

oneliners . git cherry-pick, .

+6

git add -i, , , .

add -i , , , .

+3

git add -p , @arkaitz-jimenez .

+2

, , , ( ), , .

+1

Instead of using git add -i/, git add -pyou can also use the interactive add mode git gui
(maybe other git GUIs that are in the clude commit tool, like QGit, have this function)

0
source

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


All Articles