git branch, check out question

Asked 2 years ago, Updated 2 years ago, 47 views

I studied to write Git before... I haven't used it often, but since I haven't used it in a long time, it doesn't work as I thought I forgot. Let me explain what the situation is...

Since it is a project that I am working on by myself, while I was working on A on the master branch without thinking, I found a bug that was urgent to fix in other parts, so I have to fix the bug first. Both actions have the task of modifying 'File A'. I wanted to leave the contents of work A behind and try to make a branch to proceed with work B first and distribute it.

Here's the scenario I thought of.

In this way, the working environment is separated for each branch, so I expected that I could edit 'File A' in an independent state every time I check out, but I don't think so.

How do branches and checkouts actually work? Also, what method should I use to edit the same file in different jobs at the same time as my situation?

git

2022-09-21 11:35

1 Answers

checkout is a command to move the head to the most recent commit of a particular branch. If there are files whose status has changed, such as unstaged, untracked file, or modified, move the head while maintaining the change point.

Therefore, to separate tasks by branch, you must save the current branch's work with stash or commit before moving the branch and then checkout.

checkout may fail in some cases. Typically, the branch you want to move and the change point of the current branch conflict, but you do not commit.

For an easy example:


2022-09-21 11:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.