Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simultaneously git add -p and git checkout -p

Tags:

git

I'm manually reviewing a huge number of changes (in the 1000s) made by a search and replace script over some message catalogs. At the moment I'm doing git add -p, but I keep taking breaks to check other files or adjust the script, so I'm alternating that with git checkout -p to discard the changes I don't want. Is there a way to combine the two? I.e. for each hunk I want the option to stage it, or discard it.

like image 449
ZoFreX Avatar asked Jul 18 '12 09:07

ZoFreX


People also ask

Can I work on 2 branches simultaneously?

You can have many branches in your repository, but only one of these will be "checked out" as the working-tree so that you can work on it and make changes. git worktree adds the concept of additional working trees. This means you can have two (or more) branches checked-out at once.

How do you add and checkout a branch in git?

The easiest way to create a Git branch is to use the “git checkout” command with the “-b” option for a new branch. Next, you just have to specify the name for the branch you want to create. To achieve that, you will run the “git checkout” command with the “-b” option and add “feature” as the branch name.

How do I create a new branch and checkout at the same time?

New Branches The git branch command can be used to create a new branch. When you want to start a new feature, you create a new branch off main using git branch new_branch . Once created you can then use git checkout new_branch to switch to that branch.

What happens if two people push to git at the same time?

If server detects a conflict when someone pushes data (and if two users are doing this "simultaneously" one of the pushes will be conflicting, because it will be applied only after the other one completes), the server will reject it, and the unlucky user shall then resolve conflicts and try to push again.


1 Answers

If you are using Windows or Mac OS you can use free SourceTree GUI app that allows you to stage or discard each hunk (or even select lines from each hunk) in the diff view.

Stage/Discard hunk

like image 167
Paul Avatar answered Oct 03 '22 19:10

Paul