I have a branch with hundreds of new and different files and I just want to merge a dozen or so of these into my release branch. I tried running a normal git merge with no commit and that automatically staged hundreds of files I don't want (in addition to finding dozens of conflicts that require manual merging.) I then tried to do a git revert to unstage all of the automerged files and just add the ones I want back to the index, but that also aborted the merge and leaves all the conflict markers in the files. I thought I could just run the mergetool but it now doesn't recognize the conflict markers...
Am I going about this the totally wrong way...or is there something I'm missing?
Unstage commits softly Alternatively, if you want to unstage your last commit, you can the “HEAD” notation in order to revert it easily. Using the “–soft” argument, changes are kept in your working directory and index. As a consequence, your modifications are kept, they are just not in the Git repository anymore.
Unstage Committed FilesThe git reset command can allow changes to files and directories that have already been committed.
You can use the Git reset command to undo a merge. Firstly, you need to check for the commit hash (or id) so you can use it to go back to the previous commit. To check for the hash, run git log or git reflog . git reflog is a better option because things are more readable with it.
If you've accidentally staged all your changed files you can unstage them all by using git reset . This should put you back in the state you were before staging all your changes files. Allowing you to stage changed files individually before you commit.
It's as simple as using git reset
. I was using git stash pop
and had a merge conflict and it also staged some files with changes by me and merge. I resolved the conflict and unstaged all the files with the following command:
git reset HEAD <file_1> <file_2> ... <file_n>
The question is a bit ambiguous. I'll try to rephrase it and answer accordingly. Say you want to merge only the files(file2, file3) from the branchA:
1) Get the tree sha1 of the branch commit:
git cat-file -p branchA
2) Checkout the changes under that tree for file2 and file3:
git reset <sha1> -- file2 file3
3) Commit this changes:
git commit -m 'Merge of branchA'
If you've already message with the staging, do(in case all the needed changes are committed ahead of time): git reset --hard
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With