Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » What is the proper way to stage / unstage specific lines in a diff?
What is the proper way to stage / unstage specific lines in a diff? [message #1853155] Tue, 21 June 2022 01:39 Go to next message
Cody Mikol is currently offline Cody MikolFriend
Messages: 5
Registered: December 2021
Junior Member
Hello,

Is there a way in Jgit to take a diff like so


--- a/src/test/kotlin/state/GitDownStateSpec.kt
+++ b/src/test/kotlin/state/GitDownStateSpec.kt
@@ -16,8 +16,9 @@
         val git: Git,
     ) {
 
+
         fun addFile(filename: String, content: String) = this.also {
-            val path = this.dir.toString() + "/" + filename
+            val path = this.dir.toString() + "/" +  filename
             File(path).also { file -> file.parentFile.mkdirs() }.writeText("Foo")
         }
 
@@ -51,7 +52,6 @@
         fun closeGitDownState() = this.also {
             GitDownState.git.value.close()
         }
-
     }
 
     fun createTestRepository() =



And specify that I want to stage two specific lines of the first hunk and one line of the second hunk?

Is there a way to do the inverse looking at a staged diff?

Using git, I believe these would be achieved by

git add -p

and

git reset -p

although interactively, which is not what I want.

[Updated on: Tue, 21 June 2022 02:26]

Report message to a moderator

Re: What is the proper way to stage / unstage specific lines in a diff? [message #1853370 is a reply to message #1853155] Wed, 29 June 2022 15:21 Go to previous messageGo to next message
Cody Mikol is currently offline Cody MikolFriend
Messages: 5
Registered: December 2021
Junior Member
Hope its alright that I'm bumping this.

I'm working on a free open source port of https://gitup.co/ that will work on mac / linux / windows over here: https://github.com/codymikol/git-down
This is my last hurdle at making the commit authoring piece 1:1 with the original.

Are there any seasoned developers that would be willing to spare some time consulting with me on how I could accomplish this? I'd be willing to compensate
you for your time, thank you!
Re: What is the proper way to stage / unstage specific lines in a diff? [message #1853383 is a reply to message #1853370] Thu, 30 June 2022 07:12 Go to previous message
Thomas Wolf is currently offline Thomas WolfFriend
Messages: 497
Registered: August 2016
Senior Member
Staging/unstaging are operations that modify the blob stored in the git index. If you stage a whole file, the file content is run through the clean and CRLF filters, and then stored in the index. Unstaging a whole file runs the blob in the index through the smudge and crlf filters, and replaces the file in the file system with that.

If you want to stage/unstage individual lines, you have to do the same, but instead of replacing the whole blob/file you'll have to update both by inserting/deleting the appropriate lines.
Previous Topic:JGit Maintenance
Next Topic:jgit checkout cost too long time
Goto Forum:
  


Current Time: Thu Oct 06 07:46:25 GMT 2022

Powered by FUDForum. Page generated in 0.02467 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top